To query as GROUP BY in Python Django, we can use the aggregation features in the Django ORM.
For instance, we write
from django.db.models import Count
result = (Members.objects
.values('designation')
.annotate(dcount=Count('designation'))
.order_by()
)
to get the designation
column values with values
.
Then we get the count of the designation
column values with Count
.
And then we call order_by
sort the values in ascending order.