Quantcast
Channel: RasadaCrea rss feeds aggregator
Viewing all articles
Browse latest Browse all 167

Alexey Evseev: Trap in counting related objects in Django

$
0
0
Task: for every object count number of related objects satisfying some conditions. Example: class Category(models.Model): title = models.CharField(max_length=50) class Article(models.Model): title = models.CharField(max_length=50) category = models.ForeignKey(Category) approved_at = models.DateTimeField(blank=True, null=True) Pay attention at field Article.approved_at , it contains article approval time and it can be null. Create test data: from django.utils import timezone c1 = Category.objects.create(title='c1') c2 = Category.objects ...

Viewing all articles
Browse latest Browse all 167

Trending Articles