Creating custom forms and actions
In this recipe, we will create a custom form using the forms provided by Flask-Admin
. Additionally, we will create a custom action using the custom form.
Getting ready
In the previous recipe, we saw that the edit form view for the User
record update had no option to update the password for the user. The form looked like the following screenshot:
Figure 8.8 – Built-in user edit form
In this recipe, we will customize this form to allow administrators to update the password for any user.
How to do it…
The implementation of this feature will only require changes to views.py
:
- First, start by importing
rules
from theFlask-Admin
form:from flask_admin.form import rules
In the previous recipe, we had form_edit_rules
, which had just two fields – that is, username
and admin
– as a list. This denoted the fields that will be available for editing to the admin user in the User
...