parler.admin module¶
Translation support for admin forms.
django-parler provides the following classes:
- Model support:
TranslatableAdmin. - Inline support:
TranslatableInlineModelAdmin,TranslatableStackedInline,TranslatableTabularInline. - Utilities:
SortedRelatedFieldListFilter.
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:
- The
search_fieldsneeds the actual ORM fields. - The
prepopulated_fieldsneeds to be replaced with a call toget_prepopulated_fields().
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¶ alias of
parler.forms.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= 'language'¶ The URL parameter for the language value.
-
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.htmlwhen the admin uses a translatable model.
-
default_change_form_template¶ Determine what the actual change_form_template should be.
-
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(request, object_id, language_code)¶ 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_queryset(request)¶ Make sure the current language is selected.
-
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='', obj=None)¶ Insert the language tabs.
-
response_add(request, obj, post_url_continue=None)¶ Determine the HttpResponse for the add_view stage.
-
response_change(request, obj)¶ Determine the HttpResponse for the change_view stage.
-
The TranslatableInlineModelAdmin class¶
-
class
parler.admin.TranslatableInlineModelAdmin(parent_model, admin_site)¶ Base class for inline models.
-
form¶ alias of
parler.forms.TranslatableModelForm
-
formset¶
-
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.
-
get_queryset_language(request)¶ Return the language to use in the queryset.
-
inline_tabs¶ Whether to show inline tabs, can be set as attribute on the inline.
-