Reputation: 4719
I have an SQLAlchemy query and I wish to update a specific field in all the items returned from the query something like:
items = MyModel.query().filter(
MyModel.status == 'OK',
)
with db.managed_session() as s:
items.update(status_date=datetime.today())
how can this be achieved?
Upvotes: 0
Views: 64
Reputation: 309
I usually use:
session.query(MyModel).\
filter(MyModel.status == 'OK').\
update({'status_date': datetime.today()})
I think that in your example is missing the {} in the update.
Upvotes: 1