Ticket #12193: django-doc-i18n.patch

File django-doc-i18n.patch, 1.7 KB (added by maxime.petazzoni@…, 7 years ago)

Adding a section "Notes on model classes translation" to the i18n documentation

  • docs/topics/i18n.txt

    219219            verbose_name = _('my thing')
    220220            verbose_name_plural = _('mythings')
     222Notes on model classes translation
     225Your model classes may not only contain normal fields: you may have
     226relations (with a ``ForeignKey`` field) or additional model methods you
     227may use for columns in the Django admin site.
     229If you have models with foreign keys and you use the Django admin site,
     230you can provide translations for the relation itself by using the
     231``verbose_name`` parameter on the ``ForeignKey`` object::
     233    class MyThing(models.Model):
     234        kind = models.ForeignKey(ThingKind, related_name='kinds',
     235                                 verbose_name=_('kind'))
     237As you would do for the ``verbose_name`` and ``verbose_name_plural``
     238settings of a model Meta class, you should provide a lowercase verbose
     239name text for the relation as Django will automatically titlecase it
     240when required.
     242For model methods, you can provide translations to Django and the admin
     243site with the ``short_description`` parameter set on the corresponding
     246    class MyThing(models.Model):
     247        kind = models.ForeignKey(ThingKind, related_name='kinds',
     248                                 verbose_name=_('kind'))
     250        def is_mouse(self):
     251            return self.kind.type == MOUSE_TYPE
     252        is_mouse.short_description = _('Is it a mouse?')
     254As always with model classes translations, don't forget to use the lazy
     255translation method!
Back to Top