hvad.fieldtranslator
¶
-
hvad.fieldtranslator.
TRANSLATIONS
¶ Constant to identify Shared Model classes.
-
hvad.fieldtranslator.
TRANSLATED
¶ Constant to identify Translations Model classes.
-
hvad.fieldtranslator.
NORMAL
¶ Constant to identify normal models.
-
hvad.fieldtranslator.
MODEL_INFO
¶ Caches the model informations in a dictionary with the model class as keys and the return value of
_build_model_info()
as values.
-
hvad.fieldtranslator.
_build_model_info
(model)¶ Builds the model information dictionary for a model. The dictionary holds three keys:
'type'
,'shared'
and'translated'
.'type'
is one of the constantsTRANSLATIONS
,TRANSLATED
orNORMAL
.'shared'
and'translated'
are a list of shared and translated fieldnames. This method is used byget_model_info()
.
-
hvad.fieldtranslator.
get_model_info
(model)¶ Returns the model information either from the
MODEL_INFO
cache or by calling_build_model_info()
.
-
hvad.fieldtranslator.
_get_model_from_field
(starting_model, fieldname)¶ Get the model the field
fieldname
onstarting_model
is pointing to. This function usesget_field_by_name()
on the starting model’s options (meta) to figure out what type of field it is and what the target model is.
-
hvad.fieldtranslator.
translate
(querykey, starting_model)¶ Translates a querykey (eg
'myfield__someotherfield__contains'
) to be language aware by spanning the translations relations wherever necessary. It also figures out what extra filters to the Translations Model tables are necessary. Returns the translated querykey and a list of language joins which should be used to further filter the queryset with the current language.