Getting Errors With Passing Parameters With Fliter_by Function In Sqlalchemy
I have the following class for a table in SQLalchemy class STDcodes(db.Model): id = db.Column(db.Integer, primary_key=True) stdcode = db.Column(db.Integer, nullable=False) city = d
Solution 1:
Use filter
, not filter_by
. filter_by
is a shortcut to filter
that applies the equality op to keyword args, you can't use it for other ops.
filter
takes operations, such as User.name == 'davidism'
or STDcodes.city.startswith(line)
, and applies them to the query. filter_by
is a shortcut that takes keyword arguments instead of operations, and expands them into the equivalent equality operations. So filter_by(name='davidism', superuser=True)
is equivalent to filter(User.name == 'davidism', User.superuser)
.
So filter_by
can be convenient but has limitations: all keywords are assumed to be columns on the primary model being filtered, the only operation supported is equality, and all operations are and
'd together, there's no way to use or
.
Post a Comment for "Getting Errors With Passing Parameters With Fliter_by Function In Sqlalchemy"