Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 620
Ben Kilah Avatar asked Oct 31 '13 06:10

Ben Kilah


People also ask

What is not equal to in SQLAlchemy?

The operator used for not equals is !=

What is aliased in SQLAlchemy?

Implementing alias in SQLAlchemy SQL alias is a method of giving a temporary name for a table that is more convenient and readable. SQL alias facilitates a simple name to be used in place of a complex table name when it has to be used multiple times in a query.

What is _sa_instance_state in SQLAlchemy?

_sa_instance_state is a non-database-persisted value used by SQLAlchemy internally (it refers to the InstanceState for the instance. While not directly relevant to this section, if we want to get at it, we should use the inspect() function to access it).

What is Backref in SQLAlchemy?

The sqlalchemy backref is one of the type keywords and it passed as the separate argument parameters which has to be used in the ORM mapping objects. It mainly includes the event listener on the configuration attributes with both directions of the user datas through explicitly handling the database relationships.


1 Answers

You want filter, not filter_by:

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

See this answer for more on filter vs filter_by

like image 59
DazWorrall Avatar answered Sep 21 '22 04:09

DazWorrall