hvad.admin.translatable_modelform_factory(model, form=TranslatableModelForm, fields=None, exclude=None, formfield_callback=None)

The same as django.forms.models.modelform_factory() but uses type instead of django.forms.models.ModelFormMetaclass to create the form.


class hvad.admin.TranslatableAdmin

A subclass of django.contrib.admin.ModelAdmin to be used for hvad.models.TranslatableModel subclasses.


The GET parameter to be used to switch the language, defaults to 'language', which results in GET parameters like ?language=en.


The form to be used for this admin class, defaults to hvad.forms.TranslatableModelForm and if overwritten should always be a subclass of that class.


We use 'admin/hvad/change_form.html' here which extends the correct template using the logic from django admin, see get_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_display to show available languages.

render_change_form(self, request, context, add=False, change=False, form_url='', obj=None)

Injects title, language_tabs and base_template into the context before calling the render_change_form() method on the super class. title just appends the current language to the end of the existing title in the context. language_tabs is the return value of get_language_tabs(), base_template is the return value of get_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_key or if that’s not available, use get_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.


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