Let’s say I’m building an Article / Comment system like this:
class Article(models.Model):
title = models.TextField()
content = models.TextField()
class Comment(models.Model):
article = ForeignKey(Article)
content = models.TextField()
How can I filter Article.objects to find the articles that have more than ten comments?
You need to annotate your queryset with the number of comments for each article, then filter on the annotated field.