RedaBitar
RedaBitar

Reputation: 343

Editing the details view of a model in flask admin

Is there a way to edit the details view model in flask-admin? I have searched the very bad docs and I couldn't find a way with which I would be able to display the model's details in a customized way!

Is there any reference to how the "details_view" should be used, assuming this is how I modify the details view?

If not, can anyone please explain to me how can I modify the way the info is displayed in that list? I have a "list of tags" column, and I wanna show tags separately based on certain criteria, I wanna apply some filters for example before showing them. How would I do that?

Upvotes: 1

Views: 2902

Answers (1)

utopman
utopman

Reputation: 617

custom detail view can be acheived by :

1) setting the template of the modelView you are trying to customize :

class MyModelView(AdminModelView):

    details_template = "admin/details.html"

2) Edit your custom template admin/details.html by totally overiding it with a whole new page. I guess you want to add additional information or custom fields most of the time, so you can start with a admin/details.html page that looks like :

{% extends 'admin/model/details.html' %}
{% block tail %}
    {{ super() }}
    <h1>My custom content.</h1>
{% endblock %}

By inheriting from parent template, you should have environment variable available in the template.

You may find more about available override options and such there : http://flask-admin.readthedocs.io/en/latest/api/mod_model/#flask_admin.model.BaseModelView.details_template

Upvotes: 5

Related Questions