Class Signature
TabbedModelAdmin is a mixin class that extends Django’s ModelAdmin to provide a tabbed interface. It manages navigation between tabs and handles URL routing for nested views.
Use this as a mixin with Django’s
admin.ModelAdmin. The order matters: TabbedModelAdmin should come before admin.ModelAdmin in the inheritance list.Class Attributes
The URL path segment used for tab navigation. This appears in URLs like
/admin/app/model/1/tabs/details/.List of tab classes (either
AdminTab or AdminChangeListTab subclasses) that define the available tabs for this admin interface.Methods
get_admin_tabs()
request- The Django HttpRequest objectobject_id(str) - The ID of the object being viewed
List[type] - List of tab classes
Example:
get_initial_tab()
request- The Django HttpRequest objectobject_id(str) - The ID of the object being viewed
AdminTab - An instantiated tab object
Default behavior: Returns an instance of the first tab in admin_tabs.
Example:
get_admin_tab()
request- The Django HttpRequest objectobject_id(str) - The ID of the parent objectstep(str) - The tab slug (URL-safe identifier)
Http404 if the tab slug is not found
This method automatically sets
parent_object and parent_model attributes on the tab instance.change_view()
request- The Django HttpRequest objectobject_id(str) - The ID of the object being viewedform_url(str) - Optional form URLextra_context(dict | None) - Optional additional context
HttpResponseRedirect - Redirect to the initial tab’s URL
get_context()
request- The Django HttpRequest objectinstance- The model instance being viewedstep(str) - The current tab slug
dict - Context dictionary with the following keys:
instance_meta_opts- Model meta optionsadmin_tabs- List of all tab instancescurrent_tab- The current tab sluganchor- The model instance (for navigation)
response_add()
request- The Django HttpRequest objectobj- The newly created object*args- Additional positional arguments**kwargs- Additional keyword arguments
HttpResponse - Redirect to the change view (which redirects to initial tab)
response_post_save_change()
request- The Django HttpRequest objectobj- The modified object
HttpResponseRedirect - Redirect to the current URL (refreshes the page)
get_urls()
List[URLPattern] - Combined list of tab URLs and base admin URLs
URL Patterns Created:
| Pattern | Name | View | Description |
|---|---|---|---|
<object_id>/tabs/<step>/<nested_object_id>/change/ | {app}_{model}_tab_change | nested_change_view | Change a nested object |
<object_id>/tabs/<step>/add/ | {app}_{model}_tab_add | nested_add_view | Add a nested object |
<object_id>/tabs/<step>/<nested_object_id>/delete/ | {app}_{model}_tab_delete | nested_delete_view | Delete a nested object |
<object_id>/tabs/<step>/ | {app}_{model}_step | tab_change_view | View a specific tab |
The
tabs segment can be customized using the tabs_path attribute.tab_change_view()
request- The Django HttpRequest objectobject_id(str) - The ID of the parent objectstep(str) - The tab slug
HttpResponse - The rendered tab view
nested_change_view()
request- The Django HttpRequest objectobject_id(str) - The ID of the parent objectstep(str) - The tab slugnested_object_id(str | None) - The ID of the nested object
HttpResponse - The rendered change form
This view automatically hides the delete button by setting
show_delete to False in the context.nested_add_view()
request- The Django HttpRequest objectobject_id(str) - The ID of the parent objectstep(str) - The tab slug
HttpResponse - The rendered add form
nested_delete_view()
request- The Django HttpRequest objectobject_id(str) - The ID of the parent objectstep(str) - The tab slugnested_object_id(str | None) - The ID of the nested object to delete
HttpResponse - The rendered delete confirmation or redirect