sqlalchemy - Flask-SQLAlchemy - 大于或等于

标签 sqlalchemy flask flask-sqlalchemy

我无法弄清楚如何在查询中进行“大于或等于”比较。

我有一个模型字段:

invoicedate = db.Column(db.Date(), nullable=True, key='InvoiceDate')

我正在尝试执行以下过滤器:
Invoice.query.filter_by(invoicedate >= date.today()).count()

当我运行 View 时,它不断抛出以下错误:
NameError: global name 'invoicedate' is not defined

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

最佳答案

你要filter ,不是 filter_by :

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

this answer更多关于 filter对比 filter_by

关于sqlalchemy - Flask-SQLAlchemy - 大于或等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19699756/

相关文章:

mongodb - For 循环在 Jinja/Flask 中不起作用

macos - 6000端口有什么特别之处?

python - 使用 2 个选择标准编写查询的更好方法

python - sqlalchemy,使用反向包含(不在)子列值列表中进行选择

python - SQLAlchemy 和 Google Cloud Sql session 池

python - 如何通过代码使用 Python Alembic 运行迁移?

python importlib 没有命名的模块

python - 如何在 Flask-Admin 中将方法中的访问与 BaseModelView 类分开

python - Sqlalchemy 返回 SELECT 命令的不同结果(query.all)

python - 如何使用 SQLAlchemy 根据 ID 将对象合并到 session 中,同时保持子类的正确鉴别器?