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}