SecondGear
SecondGear

Reputation: 1113

How to display text field in django_tables2

I'm using django_table2 to display data from a mysql database. One of the columns is a text column. Data from the text column is displayed without any line breaks. I know django has the linebreaks filter. My template just does {% render_table table %} so using that filter is not an option. django_tables2 has several options for different column types like tables.BooleanColumn but I don't see an option for text columns. All I'd really like to get is the line breaks to work correctly.

Upvotes: 0

Views: 1115

Answers (1)

Serafeim
Serafeim

Reputation: 15084

You can use the TemplateColumn to render any custom template in a column - for example, if you want to use the linebreaks template filter, try something like this:

class MyTable(tables.Table):
  text_field = tables.TemplateColumn('{{ record.text_field|linebreaks }}')
  ...

Upvotes: 5

Related Questions