Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

Django ORM查询。

有三个model如下:


from django.db import models

class Business(models.Model):
    name = models.CharField(max_length=10, unique=True, help_text="商户名")
    description = models.CharField(max_length=10, default="", help_text="描述")


class Merchandise(models.Model):
    title = models.CharField(max_length=10, null=True, help_text="标题")
    business = models.ForeignKey(Business, on_delete=models.CASCADE, null=True, related_name="merchandises", help_text="商户")
    total_sell = models.IntegerField(default=0, help_text="销量")


class Category(models.Model):
    name = models.CharField(max_length=10, help_text="品类名称")
    merchandises = models.ManyToManyField(Merchandise, related_name="categories", help_text="品类")

查询条件:同一商户下,同一品类的商品取销量最高的一个(同一品类指两个商品的品类只要有一个相同即可,比如A,B,C3个商品,A的品类是X,Y, B的品类是X, C的品类是X,Z,那么A商品下的推荐,就是B或C中的一个),哪位大佬可以帮忙看看。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...