在Django,我知道使用
filter
多个参数转换成SQL
AND
条款。从Django的书中:
可以将多个参数传递到
filter()缩小范围
进一步:
>>> Publisher.objects.filter(country="U.S.A.", state_province="CA")
[<Publisher: Apress>]
这些多重论点得到
转换为SQL和子句。因此,
代码段中的示例
转化为以下内容:
SELECT id, name, address, city, state_province, country, website
FROM books_publisher
WHERE country = 'U.S.A.'
AND state_province = 'CA';
如何创建转换为SQL的django查询集
OR
条款?例如:
SELECT id, name, address, city, state_province, country, website
FROM books_publisher
WHERE state_province = 'AZ'
OR state_province = 'CA';