Skip to Main Content
Learning Flask Framework
book

Learning Flask Framework

by Matt Copperwaite, Charles Leifer
November 2015
Beginner content levelBeginner
250 pages
5h 16m
English
Packt Publishing
Content preview from Learning Flask Framework

Exposing models through the Admin

Flask-Admin comes with a contrib package that contains special view classes designed to work with SQLAlchemy models. These classes provide out-of-the-box create, read, update, and delete functionalities.

Open admin.py and update the following code:

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

from app import app, db
from models import Entry, Tag, User

admin = Admin(app, 'Blog Admin')
admin.add_view(ModelView(Entry, db.session))
admin.add_view(ModelView(Tag, db.session))
admin.add_view(ModelView(User, db.session))

Note how we call admin.add_view() and pass instances of the ModelView class, as well as the db session, for it to access the database with. Flask-Admin works by providing ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Framework Cookbook - Second Edition

Flask Framework Cookbook - Second Edition

Shalabh Aggarwal
Flask Framework Cookbook

Flask Framework Cookbook

Shalabh Aggarwal

Publisher Resources

ISBN: 9781783983360Supplemental Content