My model:
class Device(models.Model):
build = models.CharField()
name = models.CharField()
How do I build my queryset so I can get the count of objects with different builds.
For example if there were two builds 'build 1' and 'build 2', I would want an output that would tell me
build 1 = 3
build 2 = 4
EDIT: Tried the following:
Device.objects.values('build').annotate(count=Count('pk'))
the output is:
[{'build': u'wed build'}, {'build': u'red build'}, ... ]
from django.db.models import Count
Device.objects.values('build').annotate(count=Count('pk'))
# -> [{'build': '1', 'count': 3}, {'build': '2', 'count': 4}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With