I have a Django project where my Manifests model consists of item codes and quantity. I want to loop through the model and find the total quantity for each item code. So I have the following in my view:
manifest = Manifests.objects.all()
How could I use a for loop or something to total the quantity for each item code. Or more clearly, if item code 10 is there 3 times with quantities = 1, 2, and 3. Total should be 6 for item code 10, and if item code 20 is there twice with quantities = 2 and 5 total should be 7.
Here is the model for reference:
models.py
class Manifests(models.Model):
reference = models.IntegerField()
quantity = models.IntegerField()
item_code = models.ForeignKey(Products, default=None, blank=True, null=True)