table production
code | part | qty | process_id |
---|---|---|---|
1 | 21 | 10 | 10 |
1 | 22 | 12 | 10 |
2 | 22 | 15 | 10 |
1 | 21 | 10 | 12 |
1 | 22 | 12 | 12 |
I have to extract data like based on process, every process has multiple part but I can't take every part's data, so that have to distinct on code for getting process wise summation of qty. how to get data like this in postgresql or in django
process_id | qty |
---|---|
10 | 27 |
12 | 12 |
I tried in this way
Production.objects.values('process').distinct('code').annotate(total_qty=Sum('quantity'))