【发布时间】:2015-01-12 17:45:39
【问题描述】:
我可以在下面查询我的数据库以获得我想要的结果,但我不想遍历所有作者对象,只是那些有多个帖子的对象。作者和帖子之间存在多对多关系,帖子上的多对多字段。有谁知道如何提高效率?
for author in Author.objects.all():
if len(author.post_set.all()) > 0:
print author
【问题讨论】:
标签: python django django-models many-to-many