Search code examples
pythonpeewee

How do you run an OR query in Peewee ORM?


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?


Solution

  • 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')
    ... )