Paul's Programming Notes     Archive     Feed     Github

Add user_id for modified_by field before save - Flask-Admin


In Flask-Admin, you can override the "on_model_change" function to to automatically populate a "modified_by" field in your model.

class LocationView(ModelView):
def on_model_change(self, form, model):
model.user_id = g.user.id

admin = Admin(app)
admin.add_view(LocationView(Location, db.session, name="Locations"))