【发布时间】:2018-12-17 08:09:14
【问题描述】:
我想用“and”逻辑过滤具有 2 个条件的模型。我也尝试过使用链式过滤器和 Q 方法,但没有得到想要的结果。它的工作原理是“或”逻辑。请帮忙。
我试过了:
Products.objects.order_by('Name').values('Name', 'UPC', 'ProductPrice', 'SubDeptNumber', 'CategoryNumber', 'FirstCompPrice', 'SecondCompPrice', 'ThirdCompPrice').filter(Name_icontains="Land", UPC_contains="15")
和
p = Products.objects.order_by('Name').values('Name', 'UPC', 'ProductPrice', 'SubDeptNumber', 'CategoryNumber', 'FirstCompPrice', 'SecondCompPrice', 'ThirdCompPrice').filter(Name_icontains="Land")
result = p.filter(UPC_contains="15")
我得到的结果显示所有 UPC 包含“15”的记录,即使名称不包含“Land”
【问题讨论】:
-
您能分享一下到目前为止您尝试过的内容吗?
-
欢迎,为了改善您在 Stack Overflow 上的体验,请阅读 how to ask 和 On Topic question,以及 Question Check list 和 the perfect question 以及如何创建 Minimal, Complete, and Verifiable example,如果尚未完成, take the tour.
标签: python django filter logical-operators