user4981459
user4981459

Reputation:

Django group by multiple column and get count of unique combination

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

Answers (1)

lucutzu33
lucutzu33

Reputation: 3700

from django.db.models import Count

YourModel.objects.values('department', 'city', 'state', 'zip').annotate(count=Count('id'))

Upvotes: 2

Related Questions