我正在尝试实现一种方法,该方法将添加到列' editing - date‘中的另一列的编辑日期。就像我在一行中更改用户名,同时在‘date date’上出现类似'23.08.18‘的内容。做这件事最好的方法是什么?
发布于 2018-08-22 00:56:34
首先,在模型中将editing_date定义为DateTime列。
然后,您可以在您的模型视图类定义中覆盖on_model_change()方法。只需将以下代码放入您的模型视图类中
from datetime import datetime
on_model_change(form, model, is_created):
if not is_created: # True if model was created and to False if edited
# you only want this to run when model is edited so we are using not operator
model.edit_date = datetime.utcnow()在创建或更新模型以及将更改提交到数据库之前,on_nodel_view()会执行一些操作。只要您想在将更改提交到数据库之前运行额外的代码,就可以使用此选项
发布于 2018-08-22 03:55:13
在模型中定义一个列,如下所示:
editing_date = db.Column(db.DateTime, onupdate=datetime.utcnow)https://stackoverflow.com/questions/51951686
复制相似问题