Saturday, November 14, 2015

Re: Fixed column width in admin interface?

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

Le samedi 14 novembre 2015 10:49:09 UTC-5, Jorge Fernandez-de-Cossio-Diaz a écrit :
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?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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.

No comments:

Post a Comment