parler.fields module¶
All fields that are attached to the models.
The core design of django-parler is to attach descriptor fields to the shared model, which then proxies the get/set calls to the translated model.
The TranslatedField
objects are automatically added to the shared model,
but may be added explicitly as well. This also allows to set the any_language
configuration option.
It’s also useful for abstract models; add a TranslatedField
to
indicate that the derived model is expected to provide that translatable field.
The TranslatedField
class¶
-
class
parler.fields.
TranslatedField
(any_language=False)¶ Proxy field attached to a model.
The field is automatically added to the shared model. However, this can be assigned manually to be more explicit, or to pass the
any_language
value. Theany_language=True
option causes the attribute to always return a translated value, even when the current language and fallback are missing. This can be useful for “title” attributes for example.Example:
from django.db import models from parler.models import TranslatableModel, TranslatedFieldsModel class MyModel(TranslatableModel): title = TranslatedField(any_language=True) # Add with any-fallback support slug = TranslatedField() # Optional, but explicitly mentioned class MyModelTranslation(TranslatedFieldsModel): # Manual model class: master = models.ForeignKey(MyModel, related_name='translations', null=True) title = models.CharField("Title", max_length=200) slug = models.SlugField("Slug")
-
__init__
(any_language=False)¶ Initialize self. See help(type(self)) for accurate signature.
-