[Answered ]-Cant figure out right queryset for json in django

2👍

You could do this with annotate function, like,

Details.objects.values('Group', 'months').annotate(count=Count('Group')).order_by('months')

Output would be,

<QuerySet [{'count': 5, 'months': 'December', 'Group': 'group1'},
    {'count': 3, 'months': 'December', 'Group': 'group3'},
    {'count': 10, 'months': 'June', 'Group': 'group1'}, 
    {'count': 10, 'months': 'May', 'Group': 'group1'}, 
    {'count': 6, 'months': 'May', 'Group': 'group3'}]>

Count would be the number of people in a group for a specific month, regardless of the Shift they work.

Hope, this is what you were looking for,

Leave a comment