summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorTimo Graham <timograham@gmail.com>2010-12-29 15:39:12 +0000
committerTimo Graham <timograham@gmail.com>2010-12-29 15:39:12 +0000
commitec38c88dfb7f737377297c56810cd44111270255 (patch)
tree18a475faf8eab77cbea0cae540e3348c2dd0c7b6 /docs
parentaa1b537b118fbc0417b990f61bff2850ca6cad1c (diff)
Fixed #12193 - Add details to the i18n documentation for translation of model classes (relations and methods). Thanks Maxime Petazzoni and Ramiro for work on the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15102 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/i18n/internationalization.txt33
1 files changed, 33 insertions, 0 deletions
diff --git a/docs/topics/i18n/internationalization.txt b/docs/topics/i18n/internationalization.txt
index 6b728d5f8e..fffdd28812 100644
--- a/docs/topics/i18n/internationalization.txt
+++ b/docs/topics/i18n/internationalization.txt
@@ -312,6 +312,39 @@ name::
verbose_name = _('my thing')
verbose_name_plural = _('mythings')
+Notes on model classes translation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Your model classes may not only contain normal fields: you may have relations
+(with a ``ForeignKey`` field) or additional model methods you may use for
+columns in the Django admin site.
+
+If you have models with foreign keys and you use the Django admin site, you can
+provide translations for the relation itself by using the ``verbose_name``
+parameter on the ``ForeignKey`` object::
+
+ class MyThing(models.Model):
+ kind = models.ForeignKey(ThingKind, related_name='kinds',
+ verbose_name=_('kind'))
+
+As you would do for the ``verbose_name`` and ``verbose_name_plural`` settings of
+a model Meta class, you should provide a lowercase verbose name text for the
+relation as Django will automatically titlecase it when required.
+
+For model methods, you can provide translations to Django and the admin site
+with the ``short_description`` parameter set on the corresponding method::
+
+ class MyThing(models.Model):
+ kind = models.ForeignKey(ThingKind, related_name='kinds',
+ verbose_name=_('kind'))
+
+ def is_mouse(self):
+ return self.kind.type == MOUSE_TYPE
+ is_mouse.short_description = _('Is it a mouse?')
+
+As always with model classes translations, don't forget to use the lazy
+translation method!
+
Working with lazy translation objects
-------------------------------------