Paul's Programming Notes PostsRSSGithub

Create and edit records in a modal - Flask-Admin

By default Flask-Admin sends you to a separate page to create or edit a record. I added options to do it in a modal on top of the list instead.

class UserView(ModelView):
    create_modal = True
    edit_modal = True

Set those and the New and Edit buttons open the form in a popup, submit through the normal flow, and drop you back on the list. Edit came first (#919), then create (#925). Getting the create modal right meant fixing a few things: missing CSS/JS when a submit came back with validation errors, the Bootstrap 3 backdrop showing through, and translations for the modal header.

I also added a read-only details view and moved the modal markup into its own templates so the create, edit, and details modals could share it (#942), and wired the same modals into FileAdmin (#933).