hvad.utils

hvad.utils.combine(trans, klass)

Combines a Shared Model with a Translations Model by taking the Translations Model and setting it onto the Shared Model‘s translations cache.

klass is the Shared Model class. Thie argument is required as there is no way to distinguish a translation of a proxy model from that of a concrete model otherwise.

hvad.utils.get_cached_translation(instance)

Returns the cached translation from an instance or None. Encapsulates a getattr() using the model’s translations_cache.

hvad.utils.get_translation(instance, language_code=None)

Returns the translation for an instance, in the specified language. If given language is None, uses get_language() to get current language.

Encapsulates a getattr() using the model’s translations_accessor and a call to its get() method using the instance’s primary key and given language_code as filters.

hvad.utils.get_translation_aware_manager(model)

Returns a manager for a normal model that is aware of translations and can filter over translated fields on translated models related to this normal model.

class hvad.utils.SmartGetFieldByName

Smart version of the standard get_field_by_name() on the options (meta) of Django models that raises a more useful exception when one tries to access translated fields with the wrong manager.

__init__(self, real)
__call__(self, meta, name)
hvad.utils.permissive_field_by_name(self, name)

Returns the field from the Shared Model or Translations Model, if it is on either.