Published
- 1 min read
django queryset group by count
The solution for this is noted below
django queryset group by count
Solution
from django.db.models import Count
result = Books.objects.values('author')
.order_by('author')
.annotate(count=Count('author'))
Try other methods by searching on the site. That is if this doesn’t work