Unfold Admin Module
Django-CFG’s Unfold Admin Module wraps the django-unfold package with a type-safe UnfoldConfig Pydantic model, a dynamic navigation manager, OKLCH-based color theming synchronized with the Next.js UI package, and a system monitoring widget.
Features
- Type-safe configuration —
UnfoldConfigPydantic v2 model with full field validation - Dynamic navigation —
NavigationSectionandNavigationItemwith auto URL resolution and permission callbacks - OKLCH color theming — semantic color palette (
primary,success,warning,danger,info) synchronized with the frontend UI package - Auto-injected CSS — CSS variables are base64-encoded and injected at startup without static file serving
- Login autofill — dev/demo credential prefill with smart environment detection
- System monitor — CPU, memory, and process metrics accessible from admin views
- Site dropdown — configurable header dropdown menu via
SiteDropdownItem
Quick Start
# config.py
from django_cfg import DjangoConfig
from django_cfg.modules.django_unfold.models import UnfoldConfig
class MyConfig(DjangoConfig):
unfold = UnfoldConfig(
site_title="My Project Admin",
site_header="My Project Administration",
site_symbol="settings",
)Django-CFG adds unfold to INSTALLED_APPS before django.contrib.admin automatically when UnfoldConfig is set.
UnfoldConfig Fields
Site Branding
| Field | Type | Default | Description |
|---|---|---|---|
site_title | str | "Django-CFG Admin" | Title shown in browser tab |
site_header | str | "Django Config Toolkit" | Header text at the top of admin |
site_subheader | str | "Type-safe Django Configuration" | Subheader text |
site_symbol | str | "settings" | Material Symbols icon name |
site_url | str | "/" | URL for the “View site” link |
UI Settings
| Field | Type | Default | Description |
|---|---|---|---|
show_history | bool | True | Show object change history |
show_view_on_site | bool | True | Show “View on site” links |
show_back_button | bool | False | Show back button in change forms |
theme | "light" | "dark" | "auto" | None | None | Force theme or None for user switcher |
border_radius | str | "8px" | Border radius for UI elements |
Dashboard
| Field | Type | Default | Description |
|---|---|---|---|
dashboard_enabled | bool | True | Enable custom dashboard |
environment_callback | Optional[str] | "django_cfg.routing.callbacks.environment_callback" | Dotted path to environment badge callback |
Navigation Sidebar
| Field | Type | Default | Description |
|---|---|---|---|
show_search | bool | True | Show search input in sidebar |
command_search | bool | True | Enable command palette (⌘K) |
show_all_applications | bool | True | Show all installed apps in sidebar |
navigation | List[NavigationSection] | [] | Custom navigation sections |
Login Autofill
| Field | Type | Default | Description |
|---|---|---|---|
dev_autofill_email | Optional[str] | None | Email to pre-fill in login form |
dev_autofill_password | Optional[str] | None | Password to pre-fill in login form |
dev_autofill_force | bool | False | Force autofill even in production |
Site Dropdown
| Field | Type | Default | Description |
|---|---|---|---|
site_dropdown | List[SiteDropdownItem] | [] | Items in the header dropdown |
Navigation
Use NavigationSection and NavigationItem to build a structured sidebar:
from django_cfg.modules.django_unfold.models import (
UnfoldConfig,
NavigationSection,
NavigationItem,
)
class MyConfig(DjangoConfig):
unfold = UnfoldConfig(
site_title="My Admin",
navigation=[
NavigationSection(
title="Content",
separator=True,
collapsible=True,
items=[
NavigationItem(
title="Posts",
icon="article",
link="admin:blog_post_changelist",
),
NavigationItem(
title="Categories",
icon="category",
link="admin:blog_category_changelist",
),
],
),
NavigationSection(
title="Users",
items=[
NavigationItem(
title="All Users",
icon="people",
link="admin:auth_user_changelist",
),
],
),
],
)NavigationSection Fields
| Field | Type | Default | Description |
|---|---|---|---|
title | str | required | Section heading |
separator | bool | True | Show horizontal separator above section |
collapsible | bool | True | Allow collapsing the section |
open | bool | False | Start expanded by default |
items | List[NavigationItem] | [] | Navigation items |
NavigationItem Fields
| Field | Type | Default | Description |
|---|---|---|---|
title | str | required | Item label |
icon | Optional[str] | None | Material Symbols icon name |
link | Optional[str] | None | URL or Django URL name (e.g., admin:app_model_changelist) |
badge | Optional[str] | None | Dotted path to badge callback function |
permission | Optional[str | Callable] | None | Dotted path or callable for access control |
type | NavigationItemType | LINK | Item type: LINK, SEPARATOR, GROUP |
Automatic URL resolution: if link is a Django URL name (not starting with / or http), it is resolved via reverse_lazy. If the name follows the pattern admin:{app}_{model}_changelist, a permission callback is auto-generated that checks {app}.view_{model}.
Color Theming
Colors are specified in OKLCH format to be compatible with Unfold’s color-mix() CSS. The full semantic palette is defined in UnfoldConfig.get_color_scheme() and includes 10-step scales for:
primary— blue (#3b82f6/oklch(62.3% .214 259.815))success— green (#22c55e)warning— amber (#f59e0b)danger— red (#ef4444)info— sky blue (#0ea5e9)base— neutral graysfont— semantic text colors for light and dark mode
These colors are synchronized with the @djangocfg/ui-core package CSS variables.
Login Autofill
Autofill is active when any of these conditions are true:
DEBUG=Trueconfig.is_developmentisTruedev_autofill_force=True
unfold = UnfoldConfig(
site_title="Demo Admin",
dev_autofill_email="[email protected]",
dev_autofill_password="demo123",
dev_autofill_force=True, # works in production for demo sites
)Never use dev_autofill_force=True on production sites with real user data. The credentials are visible in your source code — use dedicated demo accounts only.
System Monitor
from django_cfg.modules.django_unfold import get_system_monitor
monitor = get_system_monitor()
metrics = monitor.get_system_metrics()
# Returns CPU %, memory %, disk %, load average, uptime, process countSee Also
- Changelog — recent updates to the Unfold module