81

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?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Ben Kilah
  • 3,445
  • 9
  • 44
  • 56

1 Answers1

143

You want filter, not filter_by:

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

See this answer for more on filter vs filter_by

Community
  • 1
  • 1
DazWorrall
  • 13,682
  • 5
  • 43
  • 37