[Solved]-How to translate function names in the Django admin?

21👍

The example on the page that you linked to shows that the callable can have an attribute short_description, which is the string used as the title of the column. I haven’t checked, but I strongly suspect that if you set that to a translatable string then it will work.

def colored_name(self):
    return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
colored_name.allow_tags = True
colored_name.short_description = _("Colored Name")

-3👍

it’s a function (a “callable”) so the correct syntax should be

list_display = ('first_name', 'last_name', colored_name)

Leave a comment