verbose_name for a model's method
Posted
by mawimawi
on Stack Overflow
See other posts from Stack Overflow
or by mawimawi
Published on 2010-05-23T18:55:15Z
Indexed on
2010/05/23
19:01 UTC
Read the original article
Hit count: 263
How can I set a verbose_name for a model's method, so that it might be displayed in the admin's change_view form?
example:
class Article(models.Model):
title = models.CharField(max_length=64)
created_date = models.DateTimeField(....)
def created_weekday(self):
return self.created_date.strftime("%A")
in admin.py:
class ArticleAdmin(admin.ModelAdmin):
readonly_fields = ('created_weekday',)
fields = ('title', 'created_weekday')
Now the label for created_weekday is "Created Weekday", but I'd like it to have a different label which should be i18nable using ugettext_lazy as well.
I've tried
created_weekday.verbose_name=...
after the method, but that did not show any result. Is there a decorator or something I can use, so I could make my own "verbose_name" / "label" / whateverthename is?
© Stack Overflow or respective owner