How to get the original value of changed fields?

帅比萌擦擦* 提交于 2019-11-29 04:06:27

\To see if user has been modified you can check if user in session.dirty. If it is and you want to undo it, you can execute

session.rollback()

but be advised that this will rollback everything for the session to the last session.commit().

If you want to get the original values and memory serves me correctly, it's the second element of the tuple returned by the sqlalchemy.orm.attributes.get_history utility function. You would have to do

old_value = sqlalchemy.orm.attributes.get_history(user, 'attribute')[2]

for each attribute that you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!