Reputation:
In my model there are 10 fields, out of which below four I need to group on,
department city state zip
And then get count of records which has same combination of these values
Example IT|Portland|Oregon|11111 => 100
I tried annotate however it is not giving me desired results. Please advice
Upvotes: 1
Views: 436
Reputation: 3700
from django.db.models import Count
YourModel.objects.values('department', 'city', 'state', 'zip').annotate(count=Count('id'))
Upvotes: 2