Home > front end >  Django ORM query
Django ORM query

Time:09-16

There are three model:
 
The from the django. Db import models


The class Business (models. Model) :
Name=models. CharField (max_length=10, unique=True, help_text="merchant name")
Description=models. CharField (max_length=10, default="", help_text=" description ")


The class Merchandise (models. Model) :
Title=models. CharField (max_length=10, null=True, help_text="title")
Business=models. ForeignKey (business, on_delete=models. The CASCADE, null=True, related_name="merchandises," help_text="merchants")
Total_sell=models. IntegerField (default=0, help_text="sales")


Class Category (models. Model) :
Name=models. CharField (max_length=10, help_text="category name")
Merchandises=models. ManyToManyField (Merchandise, related_name="categories", help_text="category")


Query requirements: under the same merchants, the same category, sales of goods take the highest one (the same category refers to the category of two goods that can be as long as there is A same such as A, B, C3 is A commodity, A category is the X, Y, and the category B is X, C category is X, Z, so A commodity under the recommend, is one of the B or C)
  • Related