Pergunta

I want to dynamically OR multiple clauses when performing a query. I see in the peewee documentation that:

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? Does anyone have any example code?

Foi útil?

Solução

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))
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top