擅长:python、mysql、java
<p>您需要<a href="https://docs.djangoproject.com/en/dev/topics/db/aggregation/#generating-aggregates-for-each-item-in-a-queryset" rel="nofollow">annotate</a>您的queryset为每篇文章设置注释的数量,然后在注释字段上进行筛选。你知道吗</p>
<pre><code>from django.db.models import Count
Article.objects.annotate(num_comments=Count('comment')).filter(num_comments__gt=10)
</code></pre>