Modify on-the-fly verbose_name in a model field on django admin

Posted by PerroVerd on Stack Overflow See other posts from Stack Overflow or by PerroVerd
Published on 2010-05-20T10:09:57Z Indexed on 2010/05/20 10:10 UTC
Read the original article Hit count: 437

Hi

I have this sample model working with the admin

class Author(models.Model):
    name = models.CharField(_('Text in here'), max_length=100)

with verbose_name set as ugettext_lazy 'Text in here', but sometimes, depending on the site_id i want to present a diferent verbose name, so I modified the init in this way

def __init__(self, *args, **kwargs):
    super(Author, self).__init__(*args, **kwargs)
    #some logic in here
    self._meta.get_field('name').verbose_name = _('Other text')

It works, displaying the 'Other text' instead the 'Text in here'... except for the very first time the author/add view is used.

¿Is it the right way to do it? ¿How can i fix the first time problem?

Thanks in advance

© Stack Overflow or respective owner

Related posts about django

Related posts about django-admin