For example
class Rice(models.Model):
quantity = models.DecimalField(...)
Lets say:
rices = Rice.objects.all()
for i in rices:
i.quantity
This gives output as : 5 7 9 10
Now what i want to achieve is a total_quantity till that object is reached what my desired output should be : 5 12 21 31
Logic: First object total_quantity till that object is calculated is 0+5 then, next object total_quantity is 0+5+7 then 0+5+7+9 and so on.
And this should be done using (queryset) annotate/aggregate or any other db models functions. (If not possible then any other way)
If the order changes the the output should also change.