API Reference¶
TranslatedVirtualField¶
-
class
modeltrans.fields.TranslatedVirtualField(original_field, language=None, *args, **kwargs)[source]¶ A field representing a single field translated to a specific language.
Parameters: - original_field – The original field to be translated
- language – The lanuage to translate to, or
Noneto track the current active Django language.
TranslationField¶
-
class
modeltrans.fields.TranslationField(fields=None, required_languages=None, virtual_fields=True, *args, **kwargs)[source]¶ This model field is used to store the translations in the translated model.
Parameters: - fields (iterable) – List of column names to make translatable.
- required_languages (iterable) – List of languages required for the model.
- virtual_fields (bool) – If False, do not add virtual fields to access
translated values with.
Set to
Trueduring migration from django-modeltranslation to prevent collisions with it’s database fields while having thei18nfield available.
MultiLingualManager¶
-
class
modeltrans.manager.MultilingualManager[source]¶ When adding the
modeltrans.fields.TranslationFieldto a model, MultilingualManager is automatically mixed in to the manager class of that model.
MultilingualQuerySet¶
-
class
modeltrans.manager.MultilingualQuerySet(model=None, query=None, using=None, hints=None)[source]¶ Extends
Querysetand makes the translated versions of fields accessible through the normal queryset methods, analogous to the virtual fields added to a translated model:<field>allow getting/setting the default language<field>_<lang>(for example,<field>_de) allows getting/setting a specific language. Note that ifLANGUAGE_CODE == 'en',<field>_enis mapped to<field>.<field>_i18nfollows the currently active translation in Django, and falls back to the default language.
When adding the
modeltrans.fields.TranslationFieldto a model, MultilingualManager is automatically mixed in to the manager class of that model.