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::