Search code examples
htmlcsstwitter-bootstrapflaskflask-admin

Formatting data in table


Currently using flask-admin, my data is quite long per column, i'm wondering how to format it so each line goes underneath after a certain length. So instead of

FirstName

johndoeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

transform it into this format.

FirstName

johndoeeeeee

eeeeeeeeeeee

eeeeeeeeeeee


Solution

  • import textwrap
    
    def _format_original_filename(view, context, model, name):
            formatted_original_name = textwrap.fill(model.original_name, 25)
            return formatted_original_name
    
    column_formatters = {"original_name": _format_original_name}
    

    this allowed me to wrap the string so it doesn't exceed the length view.