Re: Question about Aggregates and Annotations

2009-09-26 Thread Derek Willis
How about using filter() before annotate() Topic.objects.filter(subtopics__trashed_at__isnull=true, subtopics__complete_at__isnull=True).annotate(Count('subtopics')) That filters out the records you don't want and then performs the annotation on the remaining set. On Sep 26, 6:04 am, "oliver.an

Question about Aggregates and Annotations

2009-09-26 Thread oliver.andrich
Hi, is it possible to constrain a Count aggregate by adding some extra filters? I have a model which has a self referentiell foreign key. class Topic(models.Model): ... topic = models.ForeignKey('self', related_name='subtopics', null=True, blank=True) ... Now I wo