Registering models with Flask-Admin

In the last recipe, we saw how to get started with the Flask-Admin extension to create admin interfaces/views to our application. In this recipe, we will see how to implement admin views for our existing models with the facilities to perform CRUD operations.

Getting ready

We will extend our application from the last recipe to include an admin interface for the User model.

How to do it…

Again, with Flask-Admin, registering a model with the admin interface is very easy. We just need to add a single line of code to get this:

from flask.ext.admin.contrib.sqla import ModelView

# Other admin configuration as shown in last recipe
admin.add_view(ModelView(views.User, db.session))

Here, in the first line, we imported ModelView ...

Get Flask Framework Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.