Skip to content

Commit

Permalink
docs: mention creating models manually
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed Jul 7, 2014
1 parent 8fa38ba commit ce6b6ae
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,41 @@ There are a few solutions to this problem:
Note that the same `ORM restrictions <https://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships>`_ 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::

Expand Down

0 comments on commit ce6b6ae

Please sign in to comment.