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 !
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With