Is there a way to limit the size (length/width) of a ModelView column? I am using a WYSIWYG editor and this creates really long text, therefor making the column for the ModelView very long.
Here is picture of what it looks like. Look on the right hand side the last column. It is even longer than the screenshot could handle.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With