I have a model:
class A(models.Model):
name = models.CharField()
price = models.IntegerField()
I need to aggregate Sum of all records in db but before it I want to remove duplicates by name (distinct)
So i try use
A.objects.all().distinct('name').aggregate(total=Sum('price')
But I got error
NotImplementedError: aggregate() + distinct(fields) not implemented.
So, How can I achieve same result in django orm?
Example of table:
| name | price |
Nick | 100 |
Eva | 200 |
Nick | 100 |
I want to select all unigue values by name and than Sum price. The result is a simple number. 300 in this example.