Skip to main content

Sidebar

Added in 1.0.1

The sidebar is declared on the AdminSite, not discovered from INSTALLED_APPS. AdminSidebarService resolves model and page references, applies permissions, and computes the active/expanded state.

Options​

from django.utils.translation import gettext_lazy as _

from django_chassis.enums import SidebarIconColor
from django_chassis.options import (
SidebarLinkOption,
SidebarModelItemOption,
SidebarPageItemOption,
SidebarSectionOption
)


class CustomAdminSite(ChassisAdminSiteMixin, AdminSite):
sidebar_items = (
SidebarLinkOption(
slug='docs',
label=_('Documentation'),
icon_class='fa-solid fa-book',
url_name='admin:index',
icon_color=SidebarIconColor.BLUE
),
SidebarSectionOption(
slug='catalog',
label=_('Catalog'),
icon_class='fa-solid fa-boxes-stacked',
icon_color=SidebarIconColor.SLATE,
items=[SidebarModelItemOption(model='catalog.book'), SidebarPageItemOption(page_slug='inventory')]
)
)

SidebarSectionOption​

ParameterTypeDefault
slugstrrequired
labellocalized stringrequired
icon_classFont Awesome classrequired
itemsmodel or page childrenrequired
icon_colorSidebarIconColorSLATE

SidebarModelItemOption​

ParameterTypeDefault
model'app_label.model'required
labellocalized string or Nonemodel verbose name
icon_classFont Awesome classfa-solid fa-table-list

The model must be registered on the same AdminSite. Users without model permissions do not see the item.

SidebarPageItemOption​

ParameterTypeDefault
page_slugstrrequired
labellocalized string or Nonepage label
icon_classFont Awesome class''

The page must be listed in chassis_page_classes and must be a PermissionAdminPage. PersonalAdminPage and SuperuserAdminPage cannot be sidebar children.

SidebarLinkOption​

A standalone link to a named admin URL.

ParameterTypeDefault
slugstrrequired
labellocalized stringrequired
icon_classFont Awesome classrequired
url_nameDjango URL namerequired
icon_colorSidebarIconColor or NoneNone
permissionDjango permission code or NoneNone
Added in 1.0.6

Set icon_color to color a standalone link icon without wrapping the link in a collapsible section. Set permission to hide the link from operators without that permission. The target view still controls access to its URL.

Behaviour​

  • Duplicate slugs and unknown model/page references fail validation.
  • The stock Django nav sidebar is disabled (enable_nav_sidebar = False).
  • Active/expanded state is computed from the current URL.
  • With include_users_module and include_users_sidebar (defaults), Chassis prepends the Users and groups section. Product roles are not included. See Users and access.

See also​

Built-in sidebar items​

Added in 1.0.23

Import ready-to-use options from django_chassis.sidebar and include the ones you need in sidebar_items. The site controls their order.

from django_chassis.sidebar import (
LOCALIZATION_SIDEBAR_SECTION,
OBSERVABILITY_SIDEBAR_LINK,
SETTINGS_SIDEBAR_LINK
)

sidebar_items = (LOCALIZATION_SIDEBAR_SECTION, OBSERVABILITY_SIDEBAR_LINK, SETTINGS_SIDEBAR_LINK)

Localization uses the Chassis language and translation-key admins. Observability requires its page and detail modal on the same site. Settings requires the GlobalConfig model admin on that site.