views:

127

answers:

1

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

+2  A: 

Don't modify elements of the model. There's all sorts of metaclass stuff going on in model definitions that will break things, as you have discovered.

Instead, define a custom form and change the field label in the __init__ method there.

Daniel Roseman
Perfect. When I created the custom form the verbose_name displayed in the right way. Even it works if im making the changes in the model, but as you suggested im moving all the personalization to the form to avoid breaking things.Thanks a lot
PerroVerd