nani.admin

nani.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.

TranslatableAdmin

class nani.admin.TranslatableAdmin

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

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 nani.forms.TranslatableModelForm and if overwritten should always be a subclass of that class.

change_form_template

We use 'admin/nani/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 langauges.

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 nani.manager.TranslationQueryset.language() with the current language from _language() on the queryset returned by the call to the super class and returns that queryset.

_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 django.utils.translations.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.

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

Project Versions

Table Of Contents

Previous topic

General information on django-nani internals

Next topic

nani.descriptors

This Page