Registering models with Flask-Admin
In the previous recipe, we learned how to get started with the Flask-Admin
extension to create admin interfaces/views for our application. In this recipe, we will examine 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 previous 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; perform the following steps:
- Just add the following single line of code to
auth/views.py
:from flask_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_admin.contrib.sqla
, which is provided by Flask-Admin
to integrate SQLAlchemy models.
Looking at the screenshot corresponding to the first step...