Flask-SQLAlchemy - Greater than or equal to

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?


Solution 1:

You want filter, not filter_by:

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

See this answer for more on filter vs filter_by