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
from flask.ext.admin.contrib.sqla
, which is provided by Flask-Admin to integrate SQLAlchemy models. This will create a new admin view for the User
model; the view will look like the following screenshot:
Looking at the preceding screenshot, most...