hvad.admin¶
-
hvad.admin.translatable_modelform_factory(model, form=TranslatableModelForm, fields=None, exclude=None, formfield_callback=None)¶ The same as
django.forms.models.modelform_factory()but usestypeinstead ofdjango.forms.models.ModelFormMetaclassto create the form.
TranslatableAdmin¶
-
class
hvad.admin.TranslatableAdmin¶ A subclass of
django.contrib.admin.ModelAdminto be used forhvad.models.TranslatableModelsubclasses.-
query_language_key¶ The GET parameter to be used to switch the language, defaults to
'language', which results in GET parameters like?language=en.
-
form¶ The form to be used for this admin class, defaults to
hvad.forms.TranslatableModelFormand if overwritten should always be a subclass of that class.
-
change_form_template¶ We use
'admin/hvad/change_form.html'here which extends the correct template using the logic from django admin, seeget_change_form_base_template(). This attribute should never change.
-
get_form(self, request, obj=None, **kwargs)¶ Returns a form created by
translatable_modelform_factory().
-
all_translations(self, obj)¶ A helper method to be used in
list_displayto show available languages.
-
render_change_form(self, request, context, add=False, change=False, form_url='', obj=None)¶ Injects
title,language_tabsandbase_templateinto the context before calling therender_change_form()method on the super class.titlejust appends the current language to the end of the existingtitlein the context.language_tabsis the return value ofget_language_tabs(),base_templateis the return value ofget_change_form_base_template().
-
queryset(self, request)¶ Calls
untranslated()on the queryset returned by the call to the super class and returns that queryset. This allows showing all objects, even if they have no translation in current language, at the cost of more database queries.
-
_language(self, request)¶ Returns the currently active language by trying to get the value from the GET parameters of the request using
query_language_keyor if that’s not available, useget_language().
-
get_language_tabs(self, request, available_languages)¶ Returns a list of triples. The triple contains the URL for the change view for that language, the verbose name of the language and whether it’s the current language, available or empty. This is used in the template to show the language tabs.
-
get_change_form_base_template(self)¶ Returns the appropriate base template to be used for this model. Tries the following templates:
- admin/<applabel>/<modelname>/change_form.html
- admin/<applabel>/change_form.html
- admin/change_form.html
-