Customize (override) Flask-Admin's Submit method from edit view

♀尐吖头ヾ 提交于 2019-11-29 03:55:47

You can override on_model_change method to add your custom logic. Check http://flask-admin.readthedocs.org/en/latest/api/mod_model/#flask.ext.admin.model.BaseModelView.on_model_change

makaron

I ended up overriding a save method in my Document-derived class. So now my Employee class contains this kind of code:

def save(self, *args, **kwargs):
    print 'whatever I want to do myself is here'
    return super(Employee, self).save(*args, **kwargs)

Today I found that this solution is actually nothing new and is described on StackOverflow.

But for my specific case I think Joes' answer is better. I like it more, because if I override on_model_change I invoke my custom code only if I edit database through Admin webpage; and each programmatic operation over database (like save, update) will work using native code - which is exactly what I want. If I override save method, I will be handling every save operation myself, whether It was initiated by Admin area or programmatically by the server engine.

Solved, thank you!

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