Flask-admin:内联编辑字段后如何执行操作

Flask-admin: How to do an action after inline editing a field

我定义了以下对象 (table):

models.py

class vendors_rfi(db.Model):
    vendor_id = db.Column(db.Integer, db.ForeignKey('vendors.vendorid'), primary_key = True, nullable = False, autoincrement = False)
    update_date = db.Column(db.DateTime, nullable = False, autoincrement = False, default = datetime.datetime.now)
    status = db.Column(db.String(1), nullable = False, autoincrement = False)
    current_round = db.Column(db.Integer, nullable = False, autoincrement = False)

然后,我添加视图:

main.py

class vendors_rfi_view(ModelView):
    form_base_class = FlaskForm
    column_list = [vendors.vendor_name, 'status', 'current_round', 'update_date']
    column_editable_list = ['status', 'current_round']
    edit_modal = True
    form_choices = {
        'status': [('E', 'E'), ('R', 'R'), ('N', 'N')],
        'current_round': [('0', '0'), ('1', '1'), ('2', '2')]}

现在我可以内联编辑状态和当前回合(见屏幕截图)。

screenshot

但是,如何在状态或当前回合更改后将更新日期列自动更新为 datetime.datetime.now()?

提前致谢。

我使用这样的一行来为模型的更新设置时间戳:

update_date = db.Column(db.DateTime, onupdate = datetime.utcnow)