0

Models:

Customer Table

class Customer(models.Model):
name = models.CharField(max_length=100)
email = models.CharField(max_length=30)
phone = models.CharField(max_length=12)

def __str__(self):
    return f"Customer : {self.name}"

Order Table

class Orders(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
order_date = models.DateTimeField(auto_now_add=True)
total_amount = models.PositiveIntegerField()

def __str__(self):
    return f"Customer: {self.customer.name} | Total Amount: {self.total_amount}"

Query I am using:

order = Orders.objects.values('customer__id', 'customer__name', 'customer__email',
                             'customer__phone').annotate(Sum('total_amount')).order_by('order_date')

This is the result that I am receiving from the whole record: result data

The result that I needed should be The highest total amount from each date/day. This means it should return the highest total amount per date/day and each day may contain a different number of records. For example, if we need 5 days record and each day has 10 entries (assume), then it should give us only the five highest total amount orders from five days(one record per day of the highest total amount order). hope you got my question( i tried my best to explain).

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Waseem
  • 7
  • 4

0 Answers0