models.py
class Line_items(models.Model):
id = models.AutoField(primary_key=True)
product = models.ForeignKey('Products' , on_delete=models.DO_NOTHING )
class Products(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=400 , blank=True)
category = models.ManyToManyField('Categories', through='Product_Categories', related_name='products')
class Categories(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100 , blank=True)
slug = models.CharField(max_length=200 , blank=True)
class Product_Categories(models.Model):
id = models.AutoField(primary_key=True)
product_id = models.ForeignKey(Products, on_delete=models.DO_NOTHING)
category_id = models.ForeignKey(Categories, on_delete=models.DO_NOTHING)
here are my models. where line_items contains number of orders done till now. in line_items we have connect product id with product table. but we don't have any connetion from product table to category table. ( category table contains every category and their id ).
to connect product table with category table we have created new table 'product_categories' which connects each category with their respective product.
here what we want is top performing category. category which have highest number of orders. thanks