Flask-admin get data sen

102 Views Asked by At

Task: I would like to catch data sending by flask-admin to database after fill in forms in admin panel.

I have overridden default User view as follows:

from flask_admin.contrib.sqla import ModelView

class UserModelView(ModelView):
    def is_accessible(self):
        return current_user.is_active and current_user.is_authenticated and current_user.has_role("admin")

    def _handle_view(self, name, **kwargs):
        if not self.is_accessible():
            return redirect(url_for("admin.index"))

All modifications on admin panel after save are going to database (flask-sqlalchemy) and it works fine. Now I would like to catch the data that is sending, for example: I have changed username from X to Y and click "save". I want to catch that piece of information with username = "Y" sending to database. In docs I saw that there is method:

 on_model_change(form, model, is_created)[source]

    Perform some actions before a model is created or updated.

So I think this is a place where I should put my code, but question is, how can I get that data sending from there to database?

Normally, when I fill in something on web, its form defined by me so I just use data from this form, but here its defined by flask-admin and I have to idea how to access there.

Any ideas?

0

There are 0 best solutions below