Hello,
Python version: Python 3.7.2
Django version: 2.2.3
I want to combine distinct and annotate(Sum(...)), and get the following error:
NotImplementedError: annotate() + distinct(fields) is not implemented.
To describe: I have a bunch of sales entries like:
'John', 100
'Sam', 50
'John', 200
(the model is a text field for salesperson and an integer field for sales_amount)
I want to write a query like:
res = Sales.objects.distinct('salesperson').annotate(Sum('sales_amount'))
for person in res:
print('Salesperson %s sold %d dollars' % (person.salesperson, person.sales_amount__count))
I would expect:
Salesperson John sold 300 dollars
Salesperson Sam sold 50 dollars
Instead it generates the above error. Is there a way to do this?
Thank you,
John