I try to display text with newlines in list display of admin side of Django.
class MyModelAdmin(admin.ModelAdmin):
list_display = ('example')
def example(self,obj):
return 'TYPE : %s \n RATE : %s \n FAMILY %s'
However, it is displayed without newlines like TYPE : xxx RATE : yyy FAMILY zzz.
How can I do this in Django admin ?
You have to use br instead of a
\n, and specify that this field is allowed to use html tags:Or you can use some more elegant HTML way of formatting your output (like wrapping each in a span element with a certain class, and add some css to make then render below each other).