从Django 1.1中检出annotate()函数。
http://docs.djangoproject.com/en/dev/topics/db/aggregation/#topics-db-
aggregation
示例(从上面的URL):
>>> q = Book.objects.annotate(num_authors=Count('authors'))>>> q[0].num_authors2>>> q[1].num_authors1
从Django 1.1中检出annotate()函数。
http://docs.djangoproject.com/en/dev/topics/db/aggregation/#topics-db-
aggregation
示例(从上面的URL):
>>> q = Book.objects.annotate(num_authors=Count('authors'))>>> q[0].num_authors2>>> q[1].num_authors1