2👍
✅
Something like this:
from django.db.models import Count
Post.objects.annotate(num_comments=Count('comment')).filter(num_comments__gt=5)
The method is described in the aggregation section of the docs.
👤wim
Source:stackexchange.com