I have an Orders table. And I want to write a query to this table with more than one condition. For example, I want to get an order with id field 1 and order_status field 3.
Is there a way to do this with SQL Alchemy?
P.S. I am able to check only one condition with the following query.
order = Orders.query.filter_by(restaurant_id = restaurant_id).all()
>Solution :
There are multiple ways of doing this for example if you want to apply an and operation you can simply use filter chain as below
order = Orders.query.filter(restaurant_id = restaurant_id).filter(id = 1).filter(order_status = "Status").all()
You can also use and_ and or_ to apply respective conditions like below.
cond = and_(restaurant_id = restaurant_id, id = 1)
order = Orders.query.filter(or_(cond, order_status = "Status")).all()