flask-admin: Render inline_models as list view?
Asked Answered
A

1

6

I have a Motion model which has many Votes. I display the votes as an inline_model in flask-admin. Is it possible to render the votes as a table like in the list_view template? Instead of like this:

inline_models list

Abbevillian answered 1/3, 2016 at 19:42 Comment(0)
H
0

Using using rules from flask-admin you can change the way either the create form or the edit form looks.

class View(sqla.ModelView):
    form_create_rules = {
        #for instance
        attribute1,
        rules.Header('A header'),
        attribute2
    }

If you want more customization you can also use formatters

class View(sqla.ModelView):
    form_create_rules = {
        #for instance
        attribute1,
        rules.Header('A header'),
        attribute2
    }

def _a_column_formatter(view, context, model, name):
    #returns the content of a row in h3 html tags
    return Markup('<h3>{}</h3>'.format(model.attribute))

column_formatters = {
    'ticket_name': _a_column_formatter
}

Have a look at http://flask-admin.readthedocs.io/en/latest/api/mod_model/#flask_admin.model.BaseModelView.column_formatters

Hernia answered 16/2, 2018 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.