[Answered ]-Django admin truncate words in list display

2👍

You cannot duplicate the attribute’s name, use a custom definition instead, e.g.

def get_comment(self, obj):
    return ...
get_comment.allow_tags = True
get_comment.short_description = "Comment"

Also you should use truncatewords as a function when not using in inside a template

from django.template.defaultfilters import truncatewords

def get_comment(self, obj):
    return truncatewords(obj.comment, 10)
get_comment.allow_tags = True
get_comment.short_description = "Comment"

Leave a comment