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