I have a ValuesQuerySet called data
.
I am trying to get a summary count of all the type for each object
data.values('type')
produces this output:
[{'type': u'internal'}, {'type': u'internal'}, {'type': u'external'}, {'type': u'external'}]
I want to get a breakdown like this (there can be more then just 'internal' and 'external' as choices. This could be up to 20 different types:
internal: 2
external: 2
I'm trying this but it's just returning a empty dictionary...
data.values('type').aggregate(Count('type'))
Annotate is producing undesirbale results as well:
data.values('type').annotate(Count('type'))
[{'type': u'internal', 'type_count': 1}, {'type': u'internal', 'type_count': 1}, {'type': u'external', 'type_count': 1}, {'type': u'external', 'type_count': 1}]
Models.py
class Purchase(models.Model):
type = models.ForeignKey(Types)