parler.admin module

Translation support for admin forms.

django-parler provides the following classes:

Admin classes can be created as expected:

from django.contrib import admin
from parler.admin import TranslatableAdmin
from myapp.models import Project

class ProjectAdmin(TranslatableAdmin):
    list_display = ('title', 'status')
    fieldsets = (
        (None, {
            'fields': ('title', 'status'),
        }),
    )

admin.site.register(Project, ProjectAdmin)

All translated fields can be used in the list_display and fieldsets like normal fields.

While almost every admin feature just works, there are a few special cases to take care of:

See the admin compatibility page for details.

The BaseTranslatableAdmin class

class parler.admin.BaseTranslatableAdmin

The shared code between the regular model admin and inline classes.

form

The form to use for the model.

alias of TranslatableModelForm

get_form_language(request, obj=None)

Return the current language for the currently displayed object fields.

get_language_tabs(request, obj, available_languages, css_class=None)

Determine the language tabs to show.

get_queryset(request)

Make sure the current language is selected.

get_queryset_language(request)

Return the language to use in the queryset.

query_language_key = u'language'

The URL parameter for the language value.

queryset(request)

Make sure the current language is selected.

The TranslatableAdmin class

class parler.admin.TranslatableAdmin(model, admin_site)

Base class for translated admins.

This class also works as regular admin for non TranslatableModel objects. When using this class with a non-TranslatableModel, all operations effectively become a NO-OP.

all_languages_column(object)

The language column which can be included in the list_display. It also shows untranslated languages

change_form_template

Dynamic property to support transition to regular models.

This automatically picks admin/parler/change_form.html when the admin uses a translatable model.

delete_inline_translations = True

Whether translations of inlines should also be deleted when deleting a translation.

delete_model_translation(request, translation)

Hook for deleting a translation. This calls get_translation_objects() to collect all related objects for the translation. By default, that includes the translations for inline objects.

delete_translation(*args, **kwargs)

The ‘delete translation’ admin view for this model.

deletion_not_allowed(request, obj, language_code)

Deletion-not-allowed view.

get_available_languages(obj)

Fetching the available languages as queryset.

get_form(request, obj=None, **kwargs)

Pass the current language to the form.

get_language_short_title(language_code)

Hook for allowing to change the title in the language_column() of the list_display.

get_object(request, object_id, *args, **kwargs)

Make sure the object is fetched in the correct language.

get_translation_objects(request, language_code, obj=None, inlines=True)

Return all objects that should be deleted when a translation is deleted. This method can yield all QuerySet objects or lists for the objects.

get_urls()

Add a delete-translation view.

language_column(object)

The language column which can be included in the list_display.

prefetch_language_column = True

Whether the translations should be prefetched when displaying the ‘language_column’ in the list.

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

Insert the language tabs.

The TranslatableInlineModelAdmin class

class parler.admin.TranslatableInlineModelAdmin(parent_model, admin_site)

Base class for inline models.

form

The form to use.

alias of TranslatableModelForm

formset

The formset to use.

alias of TranslatableBaseInlineFormSet

get_available_languages(obj, formset)

Fetching the available inline languages as queryset.

get_form_language(request, obj=None)

Return the current language for the currently displayed object fields.

get_formset(request, obj=None, **kwargs)

Return the formset, and provide the language information to the formset.

inline_tabs

Whether to show inline tabs, can be set as attribute on the inline.

The TranslatableStackedInline class

class parler.admin.TranslatableStackedInline(parent_model, admin_site)

The inline class for stacked layout.

The TranslatableTabularInline class

class parler.admin.TranslatableTabularInline(parent_model, admin_site)

The inline class for tabular layout.

The SortedRelatedFieldListFilter class

class parler.admin.SortedRelatedFieldListFilter(*args, **kwargs)

Override the standard RelatedFieldListFilter, to sort the values after rendering their __unicode__() values. This can be used for translated models, which are difficult to sort beforehand. Usage:

from django.contrib import admin
from parler.admin import SortedRelatedFieldListFilter

class MyAdmin(admin.ModelAdmin):

    list_filter = (
        ('related_field_name', SortedRelatedFieldListFilter),
    )