Reducing size of columns in Flask-Admin Reducing size of columns in Flask-Admin flask flask

Reducing size of columns in Flask-Admin


Don't show the column (by exclusion):

class MyView(ModelView):    column_exclude_list = ('description')

Don't show the column (by inclusion):

class MyView(ModelView):    column_list = ('rating', 'category_id', 'year', 'stock', 'image')   

Reformat the column:

class MyView(ModelView):     def _description_formatter(view, context, model, name):        # Format your string here e.g show first 20 characters        # can return any valid HTML e.g. a link to another view to show the detail or a popup window        return model.description[:20]    column_formatters = {        'description': _description_formatter,    }


A way to do this could be to override the css style of the relevant column. In the Flask-admin list.html template you find the following code for creating the columns:

{% for c, name in list_columns %}<td class="col-{{c}}">  {% if admin_view.is_editable(c) %}    {% set form = list_forms[get_pk_value(row)] %}    {% if form.csrf_token %}      {{ form[c](pk=get_pk_value(row), display_value=get_value(row, c), csrf=form.csrf_token._value()) }}    {% else %}      {{ form[c](pk=get_pk_value(row), display_value=get_value(row, c)) }}    {% endif %}  {% else %}    {{ get_value(row, c) }}  {% endif %}</td>{% endfor %}

So e.g. for column 2 you could add a max-width property to the css class col-2 to limit its width.