Admin Mixins¶
Django Site Utils provides mixin and base classes to extend the built-in capabilities of the Django admin. By default, these mixins should not alter the behavior of the Django admin in any way unless they are configured via the model admin class attributes documented below.
InlineMixins¶
This mixin class combines all of the inline mixin classes provided by Django Site Utils.
StackedInline¶
This class combines InlineMixins
with Django’s default StackedInline
admin class.
TabularInline¶
This class combines InlineMixins
with Django’s default TabularInline
admin class.
AdminAddChangeDeleteMixin¶
This mixin adds the ability to disable all add, change or delete operations for the given ModelAdmin
via class
attributes. When allowed, the normal Django permissions will still be checked. When disabled, the given operation is
never allowed, even for superusers. The following example defines a view-only admin class:
class MyModelAdmin(AdminAddChangeDeleteMixin, admin.ModelAdmin):
can_add = False
can_change = False
can_delete = False
AdminAddFormMixin¶
This mixin allows for use of a different form class when adding a new instance than the form used for changing an existing instance:
class MyModelAdmin(AdminAddFormMixin, admin.ModelAdmin):
add_form = MyModelAddForm
AdminAddViewFieldsMixin¶
This mixin allows for different fields and fieldsets to be used for add or view operations than for
change operations. Similarly to how fieldsets
and fields
work, if add_fieldsets
or view_fieldsets
are
specified, they take precedence over add_fields
and view_fields
, respectively:
class MyModelAdmin(AdminAddViewFieldsMixin, admin.ModelAdmin):
add_fields = ('name', 'slug',)
view_fields = ('name_view', 'slug_view',)
add_fieldsets = ...
view_fieldsets = ...
AdminAddViewInlinesMixin¶
This mixin allows for different inlines to be displayed for add and view operations than for change operations. The following example displays no inlines when adding a new instance, and a custom inline when the user is only allowed to view the model:
class MyModelAdmin(AdminAddViewInlinesMixin, admin.ModelAdmin):
add_inlines = []
view_inlines = [ViewRelatedInline]
AdminMixins¶
This mixin class combines all of the model admin mixin classes provided by Django Site Utils.
ModelAdmin¶
This class combines AdminMixins
with Django’s default ModelAdmin
admin class.