Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run an OR query in Peewee ORM?

Tags:

python

peewee

I'd like to run a query for a user based on username or email address.

I must be missing it, but I can't find how to run an OR query in the peewee documentation. How do you do that?

like image 963
Sean W. Avatar asked Dec 08 '22 21:12

Sean W.


1 Answers

From the documentation

If you want to express a complex query, use parentheses and python’s bitwise or and and operators:

>>> Tweet.select().join(User).where(
...     (User.username == 'Charlie') |
...     (User.username == 'Peewee Herman')
... )
like image 70
Morgan Thrapp Avatar answered Dec 22 '22 00:12

Morgan Thrapp