[Django]-Django Verbose Name & Translations

12👍

Your approach in models.py will work correctly provided you use the lazy version of gettext:

from django.utils.translation import ugettext_lazy as _

class UserClient(models.Model):
    phone_cell = PhoneNumberField(verbose_name=_('Phone (Cell)'), ...)
    ...

In fact, Django’s very own models use the same technique for translation – have look at the AbstractUser class. You can be sure this approach will work properly.

Even though verbose_name exists in database migration, it’s not used. Any code that relies on verbose_name will retrieve it from the model directly. For example, a ModelForm field’s default label will use the model’s verbose_name, and since the translation is lazy, the actual label will be translated when it is evaluated (e.g. rendering on a template).

Leave a comment