I have a function that looks like this:
def post_count(self):
return self.thread_set.aggregate(num_posts=Count(\'post\'))[\'num_posts\']
<
Yes. Just do it. This should work as expected:
self.thread_set.filter(active_status=1).aggregate(num_posts=Count('post'))['num_posts']
Any original query returns a QuerySet
, so any available methods that return QuerySets can be can be pretty much indefinitely chained together for complex criteria matches. Since aggregate()
does not return a QuerySet, you want to make sure that it is last in the chain.