| 261 | Notes on model classes translation |
| 262 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 263 | |
| 264 | Your model classes may not only contain normal fields: you may have relations |
| 265 | (with a ``ForeignKey`` field) or additional model methods you may use for |
| 266 | columns in the Django admin site. |
| 267 | |
| 268 | If you have models with foreign keys and you use the Django admin site, you can |
| 269 | provide translations for the relation itself by using the ``verbose_name`` |
| 270 | parameter on the ``ForeignKey`` object:: |
| 271 | |
| 272 | class MyThing(models.Model): |
| 273 | kind = models.ForeignKey(ThingKind, related_name='kinds', |
| 274 | verbose_name=_('kind')) |
| 275 | |
| 276 | As you would do for the ``verbose_name`` and ``verbose_name_plural`` settings of |
| 277 | a model Meta class, you should provide a lowercase verbose name text for the |
| 278 | relation as Django will automatically titlecase it when required. |
| 279 | |
| 280 | For model methods, you can provide translations to Django and the admin site |
| 281 | with the ``short_description`` parameter set on the corresponding method:: |
| 282 | |
| 283 | class MyThing(models.Model): |
| 284 | kind = models.ForeignKey(ThingKind, related_name='kinds', |
| 285 | verbose_name=_('kind')) |
| 286 | |
| 287 | def is_mouse(self): |
| 288 | return self.kind.type == MOUSE_TYPE |
| 289 | is_mouse.short_description = _('Is it a mouse?') |
| 290 | |
| 291 | As always with model classes translations, don't forget to use the lazy |
| 292 | translation method! |
| 293 | |