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

查看:63
本文介绍了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())

请参阅此答案了解更多信息filter vs filter_by

See this answer for more on filter vs filter_by

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

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