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 ...