如何在多对多字段上执行 AND 条件
我现在有两种型号
class Sale(AuthorTimeStampedModel):
product = models.ManyToManyField(
Product, related_name='sale_product', null=True, blank=True)
def __str__(self):
return f"{self.id}"
class Product(AuthorTimeStampedModel):
id = models.IntegerField()
,我想应用查询集以获取具有product_id 1和2的所有销售,
我能够找到Q功能,但它会导致或条件,但我想要和条件
I have two models
class Sale(AuthorTimeStampedModel):
product = models.ManyToManyField(
Product, related_name='sale_product', null=True, blank=True)
def __str__(self):
return f"{self.id}"
class Product(AuthorTimeStampedModel):
id = models.IntegerField()
Now I want to apply query set to get all sales which have product_id 1 and 2
I am able to find Q function but it will result or condition but I want and condition
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)