Flask-SQLAlchemy - Greater than or equal to

SqlalchemyFlaskFlask Sqlalchemy

Sqlalchemy Problem Overview


I'm having trouble figuring out how to do a "greater than or equal to" comparison in a query.

I have a model field:

invoicedate = db.Column(db.Date(), nullable=True, key='InvoiceDate')

And i'm trying to do the following filter:

Invoice.query.filter_by(invoicedate >= date.today()).count()

When I run the view, it keeps throwing the following error:

NameError: global name 'invoicedate' is not defined

What is the correct syntax for a greater than or equal filter in sqlalchemy or flask-sqlalchemy?

Sqlalchemy Solutions


Solution 1 - Sqlalchemy

You want filter, not filter_by:

Invoice.query.filter(Invoice.invoicedate >= date.today())

See this answer for more on filter vs filter_by

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen KilahView Question on Stackoverflow
Solution 1 - SqlalchemyDazWorrallView Answer on Stackoverflow