From ce6b6ae48fc31cd8eae08ffca2bc3617d01e2c5b Mon Sep 17 00:00:00 2001 From: Diederik van der Boor Date: Mon, 7 Jul 2014 13:42:26 +0200 Subject: [PATCH] docs: mention creating models manually --- docs/advanced.rst | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/advanced.rst b/docs/advanced.rst index de2da595..c85029e2 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -46,8 +46,41 @@ There are a few solutions to this problem: Note that the same `ORM restrictions `_ apply here. -Adding translated fields to an existing model: ----------------------------------------------- +Constructing the translations model manually +-------------------------------------------- + +It's also possible to create the translated fields model manually: + +.. code-block:: python + + from django.db import models + from parler.models import TranslatableModel, TranslatedFieldsModel + from parler.fields import TranslatedField + + + class MyModel(TranslatableModel): + title = TranslatedField() # Optional, explicitly mention the field + + class Meta: + verbose_name = _("MyModel") + + def __unicode__(self): + return self.title + + + class MyModelTranslation(TranslatedFieldsModel): + master = models.ForeignKey(MyModel, related_name='translations', null=True) + title = models.CharField(_("Title"), max_length=200) + + class Meta: + verbose_name = _("MyModel translation") + +This has the same effect, but also allows to to override +the :func:`~django.db.models.Model.save` method, or add new methods yourself. + + +Adding translated fields to an existing model +--------------------------------------------- Create a proxy class::