Flask-SQLAlchemy - Greater than or equal to

会有一股神秘感。 提交于 2019-11-27 17:05:58

问题


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?


回答1:


You want filter, not filter_by:

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

See this answer for more on filter vs filter_by



来源:https://stackoverflow.com/questions/19699756/flask-sqlalchemy-greater-than-or-equal-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!