2017-06-04 43 views

回答

0

上作者查詢中使用的aggregation

from django.db.models import Count 
authors_with_counts = Author.objects.all().annotate(Count('post')) 

現在,每位作者都有一個post__count屬性,其中包含作者爲其發佈的帖子數量。

+0

非常感謝! –

+0

如果它對你有幫助,請接受答案,讓未來的讀者知道它解決了問題。 –

相關問題