Django-annotate(),Count()

21 views
Skip to first unread message

Priya

unread,
Jan 12, 2023, 3:27:02 PM1/12/23
to Django users
Hi Everyone,

This is the output i get used this code 

<QuerySet [{'pid': 11, 'status': 'Completed', 'status__count': 3}, {'pid': 11, 'status': 'Hold', 'status__count': 12}, {'pid': 11, 'status': 'InProgress', 'status__count': 2}, {'pid': 11, 'status': 'New', 'status__count': 3},}] 

View.py

tasks = Task.objects.values('pid','status').annotate(Count('status')).order_by('pid').distinct()

Actually i want the output like this,

<QuerySet [{'pid': 11, 'Completed': 3, 'Hold': 12,  'InProgress': 2,'New': 3},}] 

how can i do?

Thanks in advance,
Priya
Reply all
Reply to author
Forward
0 new messages