Answer the question
In order to leave comments, you need to log in
How to get summary data for order composition Django ORM?
There are the following models:
class ProductCategory(models.Model):
name = models.CharField(max_length=50)
class Product(models.Model):
name = models.CharField(max_length=50)
category = models.ForeignKey(ProductCategory, on_delete= models.PROTECT)
class Order(models.Model):
time = models.DateTimeField(auto_now_add=True, blank=True)
pay_type = models.BooleanField()
cost = models.IntegerField()
class OrderDetail(models.Model):
order_id = models.ForeignKey(Order, on_delete=models.CASCADE)
product_id = models.ForeignKey(Product, on_delete=models.CASCADE)
count = models.IntegerField()
I get a list of orders (Order) using a filter for a certain time (start_date, stop_date).
Tell me how to get by the list of orders - a list of products that these orders consist of, and the products can be repeated in different orders and they need to be summed up. And also you need to group these products according to the categories to which they belong.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question