1
我需要從數據庫中獲得條目的評論數。我可以用django的評論框架嗎?我也使用未使用GenericForeignKeys我得到的分數條目這樣的投票應用:訂購條目通過意見計數與Django
class EntryManager(models.ModelManager):
def get_queryset(self):
return super(EntryManager,self).get_queryset(self).all().annotate(\
score=Sum("linkvote__value"))
但是,當有foreignkeys我被卡住。你有什麼想法嗎?
額外的解釋:我需要這樣獲取的條目:
id | body | vote_score | comment_score |
1 | foo | 13 | 4 |
2 | bar | 4 | 1 |
這樣做之後,我可以通過comment_score訂購。 :)
Thans爲所有答覆。
用comment_count = Count('comment')註釋不起作用? ..(你最好檢查註釋的數據庫字段是什麼..不知道django評論從內存.. – niklasdstrom
不會知道它不會 –
看看[這](https://github.com/coleifer/django-generic -聚合) – jperelli