Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (120 points)

I have a Customer Model and an Orders Model as below

class Customer(models.Model):
    id = models.AutoField(primary_key = True)
    name = models.CharField(max_length = 100)
    city = models.CharField(max_length = 100)

class Order(models.Model):
    id = models.AutoField(primary_key = True)
    value = models.FloatField(default=0.00)      customer = models.ForeignKey(Customer, on_delete = models.SET_NULL, blank = True, null = True)

Now I want to display the following information by iterating through the lists:

1] Count of Customers from each City
2] Total value of Orders from each City
3] Count of Orders from each Customer
4] Total Sum of Orders from each Customer

The above information has to be displayed in HTML tables using {% for %}{% endfor %} loop.

I've been looking for a solution to this for a long time now. Will be a great help if you an provide me the solution.

Thanks in advance.

Please log in or register to answer this question.

Browse Categories