[Django]-Django queryset group by field

4👍

You must doing something like this:

from django.db.models import Count

MyModel.objects.values('Type').annotate(dcount=Count('Type'))

MyModel.objects.values('Type__id').annotate(dcount=Count('Type__id'))

you can also read this document can help you….
good luck!

Leave a comment