class Term(models.Model):
created = models.DateTimeField(auto_now_add=True)
term = models.CharField(max_length=255)
嗨, 我嘗試次數從我的數據庫表中的重複/多個方面,但我得到的仍然是我的表中的所有項目({term: a, count: 1, term: a, count: 1,term: b, count: 1,...}
)的列表,而不是像{term: a, count: 12, term: b, count: 1}
計數多個方面
有沒有人一個主意?
編輯:
ee = Term.objects.annotate(Count("term")).values("term", "term__count")
結果:
[{'term': u'tes', 'term__count': 1}, {'term': u'tes', 'term__count': 1},
我期待什麼:
[{'term': u'tes', 'term__count': 2}, {'term': 'b', 'term__count': 1}
你試過了什麼?你是如何得到這份名單的?什麼是「計數」? –
我使用django的count方法 – Azd325
你可以發佈你的代碼,你在哪裏使用「django的count方法」? –