1

I using flask-sqlachemy. It is an extension of sqlachemy and I am not sure how _or translates to flask-sqlalchemy. For example, my query:

qry = DateModel.query.filter(
            DateModel.from_date >= f_date, 
            DateModel.from_date <= t_date).all()

Here two lines inside filter translates to AND. So I get all records between f_date and t_date.

Now I want to add more data with OR. For example:

qry = DateModel.query.filter(
            DateModel.from_date >= f_date, 
            DateModel.from_date <= t_date 

            OR?

            DateModel.to_date >= f_date, 
            DateModel.to_date <= t_date).all()

What would be the syntax for such query?

1 Answer 1

2

From this question solution with sqlachemy is below

query = session.query(DateModel).filter(
((DateModel.from_date >= f_date) &
(DateModel.from_date <= t_date)).self_group() |
((DateModel.to_date >= f_date) &
(DateModel.to_date <= t_date)).self_group()).all()

Not familiar with flask-sqlalchemy, but I'm expecting something like:

query = DateModel.query.filter(
((DateModel.from_date >= f_date) &
(DateModel.from_date <= t_date)).self_group() |
((DateModel.to_date >= f_date) &
(DateModel.to_date <= t_date)).self_group()).all()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.