9👍
✅
from django.db.models import Count
Device.objects.values('build').annotate(count=Count('pk'))
# -> [{'build': '1', 'count': 3}, {'build': '2', 'count': 4}]
4👍
A simple approach is just calling count
:
>>> Device.objects.filter(build='1').count()
3
>>> Device.objects.filter(build='2').count()
4
- [Django]-Single Django Application, Multiple Instances
- [Django]-How do you produce/create tables in Geraldo Reports?
Source:stackexchange.com