Book Image

Flask Framework Cookbook

By : Shalabh Aggarwal
Book Image

Flask Framework Cookbook

By: Shalabh Aggarwal

Overview of this book

Table of Contents (19 chapters)
Flask Framework Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating custom forms and actions


In this recipe, we will create some custom forms using the forms provided by Flask-Admin. Also, we will create a custom action using the custom form.

Getting ready

In the last 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:

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 just require changes to views.py. First, we will start by importing rules from the Flask-Admin forms:

from flask.ext.admin.form import rules

In the last 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 on the User model update view.

Updating the password is not a simple affair of just adding one more field to the list of form_edit_rules, because we...