Flask SQLAlchemy filter by value OR another

前端 未结 3 1148
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 11:29

I have a Flask project that interacts with MySQL db through Flask-SQLAlchemy.

My question is, how to select a row from the database based on a v

3条回答
  •  离开以前
    2021-01-31 12:20

    I also wanted to have an or along with and condition

    I found this after googling around:

    # Users whose age is 23 AND (firstname IS alex OR lastname IS watson)
    usrs = session.query(User) \
        .filter(User.age === "23") \
        .filter((User.firstname == 'alex') | (User.lastname == 'watson')) \
        .all()
    

    hopefully, it helps other people coming here looking for it

提交回复
热议问题