11

I have a query that require to use the "or" | operator :

Mymodel.query.filter((Mymodel.a== 'b') | (Mymodel.b == 'c'))

That works fine. However, I want my conditions to be put in an array of unkown length :

conds = [ Mymodel.a== 'b', Mymodel.b == 'c', Mymodel.c == 'd']
Mymodel.query.filter(???(conds))

Thanks !

1 Answer 1

20

You are looking for or_

conds = [ Mymodel.a== 'b', Mymodel.b == 'c', Mymodel.c == 'd']

If you have the above list of conditions just pass them all to or_

from sqlalchemy import or_
Mymodel.query.filter(or_(*conds))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.