Flask-SQLAlchemy-大于或等于 [英] Flask-SQLAlchemy - Greater than or equal to

查看:890
本文介绍了Flask-SQLAlchemy-大于或等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在弄清楚如何在查询中进行大于或等于"比较时遇到了麻烦.

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

我有一个模型字段:

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

在sqlalchemy或flask-sqlalchemy中大于或等于过滤器的正确语法是什么?

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

推荐答案

您要的是filter,而不是filter_by:

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

有关更多信息,请参见此答案filterfilter_by

See this answer for more on filter vs filter_by

这篇关于Flask-SQLAlchemy-大于或等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆