Fixed column width in admin interface?

1,580 views
Skip to first unread message

Jorge Fernandez-de-Cossio-Diaz

unread,
Nov 14, 2015, 10:49:09 AM11/14/15
to Django users
A column of my Django admin interface sometimes has too much text. When this happens, I would like to replace the last part of the text with "...", so that the column width doesn't gets past a maximum character count. How can I do this?

Simon Charette

unread,
Nov 14, 2015, 11:10:06 AM11/14/15
to Django users
Hi Jorgue,

You can simply define a `list_display` method that truncates your text if required and append an ellipsis.

e.g.

class FooAdmin(admin.ModelAdmin):
    list_display = ['text_field_ellipsis']

    def text_field_ellipsis(self, obj):
        if len(obj.text_field) > max_length:
            return "%s..." % obj.text_field[:max_length]
        return obj.text_field

Cheers,
Simon

Gergely Polonkai

unread,
Nov 14, 2015, 6:25:48 PM11/14/15
to Django users

Or you can apply a CSS with overflow: ellipsis; whichever fits you.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f86671ca-0645-4567-a3b2-1372d55f7308%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jorge Fernandez-de-Cossio-Diaz

unread,
Nov 22, 2015, 4:11:40 PM11/22/15
to Django users
Adding the `list_display` method worked. With Polonkai's solution, just for curiosity, where do I have to "apply the CSS"? I am a newbie, please give the details.
Reply all
Reply to author
Forward
0 new messages