parler.managers module

Custom generic managers

The TranslatableManager class

class parler.managers.TranslatableManager

The manager class which ensures the enhanced TranslatableQuerySet object is used.

active_translations(language_code=None, **translated_fields)

Only return objects which are translated, or have a fallback that should be displayed.

Typically that’s the currently active language and fallback language. This should be combined with .distinct().

When hide_untranslated = True, only the currently active language will be returned.

language(language_code=None)

Set the language code to assign to objects retrieved using this Manager.

queryset_class

alias of TranslatableQuerySet

translated(*language_codes, **translated_fields)

Only return objects which are translated in the given languages.

NOTE: due to Django ORM limitations, this method can’t be combined with other filters that access the translated fields. As such, query the fields in one filter:

qs.translated('en', name="Cheese Omelette")

This will query the translated model for the name field.

The TranslatableQuerySet class

class parler.managers.TranslatableQuerySet(*args, **kwargs)

An enhancement of the QuerySet which sets the objects language before they are returned.

When using this class in combination with django-polymorphic, make sure this class is first in the chain of inherited classes.

active_translations(language_code=None, **translated_fields)

Only return objects which are translated, or have a fallback that should be displayed.

Typically that’s the currently active language and fallback language. This should be combined with .distinct().

When hide_untranslated = True, only the currently active language will be returned.

iterator()

Overwritten iterator which will set the current language before returning the object.

language(language_code=None)

Set the language code to assign to objects retrieved using this QuerySet.

translated(*language_codes, **translated_fields)

Only return translated objects which of the given languages.

When no language codes are given, only the currently active language is returned.

Note

Due to Django ORM limitations, this method can’t be combined with other filters that access the translated fields. As such, query the fields in one filter:

qs.translated('en', name="Cheese Omelette")

This will query the translated model for the name field.