简体   繁体   English

python peewee动态或子句

[英]python peewee dynamically or clauses

I want to dynamically OR multiple clauses when performing a query. 我想在执行查询时动态OR多个子句。 I see in the peewee documentation that: 我在peewee文档中看到:

import operator
or_clauses = reduce(operator.or_, clauses)  # OR together all clauses

However, this note is somewhat unclear. 但是,此注释尚不清楚。 What exactly is clauses supposed to be set to? clauses应该设置为什么? Does anyone have any example code? 有人有示例代码吗?

clauses would be a list of expressions in the example, sorry that it is unclear. 子句将是示例中的表达式列表,抱歉,目前尚不清楚。

You might write something like: 您可能会写类似:

clauses = [
    (User.username == 'something'),
    (User.something == 'another thing'),
    ...
]
User.select().where(reduce(operator.or_, clauses))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM