API Reference
Complete reference for all Django Admin classes, methods, and utilities.
Core Classes
AdminConfig
Pydantic model for admin configuration.
from django_cfg.modules.django_admin import AdminConfig
class AdminConfig(BaseModel):
# Required
model: Type[Model]
# Display
list_display: List[str] = []
list_display_links: List[str] | None = None
list_editable: List[str] = [] # Fields editable directly in list view
list_per_page: int = 50
list_max_show_all: int = 200
# Display fields (auto-generate display methods)
# Accepts List[FieldConfigType] — discriminated union of all 16 field types
display_fields: List[FieldConfigType] = []
# Filters and search
# Accepts List[FilterSpec] where FilterSpec = str | type | tuple[str, type] | FilterConfig
list_filter: List[FilterSpec] = []
search_fields: List[str] = []
date_hierarchy: str | None = None
show_facets: bool = False # True = always show filter counts (ShowFacets.ALWAYS)
# Ordering
ordering: List[str] = []
# Readonly
readonly_fields: List[str] = []
# Form options
autocomplete_fields: List[str] = []
raw_id_fields: List[str] = []
prepopulated_fields: Dict[str, Tuple[str, ...]] = {}
# Performance
select_related: List[str] = []
prefetch_related: List[str] = []
annotations: Dict[str, Any] = {}
# Fieldsets
fieldsets: List[FieldsetConfig] = []
# Actions
actions: List[ActionConfig] = []
# Inlines
inlines: List[Type] = []
# Import/Export
import_export_enabled: bool = False
resource_class: Type | None = None
# Other
filter_horizontal: List[str] = []
filter_vertical: List[str] = []
formfield_overrides: Dict[Any, Dict[str, Any]] = {}
documentation: DocumentationConfig | None = None # see the Documentation page
widgets: List[WidgetConfig] = [] # e.g. JSONWidgetConfig
save_on_top: bool = False
save_as: bool = False
preserve_filters: bool = TruePydanticAdmin
Base admin class that processes AdminConfig.
from django_cfg.modules.django_admin.base import PydanticAdmin
@admin.register(MyModel)
class MyModelAdmin(PydanticAdmin):
config = my_config
# Access to HTML builder
self.html.badge(...)
self.html.span(...)
# ... etcProperties:
config: AdminConfig- Configuration instancehtml: HtmlBuilder- HTML builder utility
Base: import_export.admin.ImportExportModelAdmin over django.contrib.admin.ModelAdmin
(get_base_admin_class() returns it). Extra class attributes on top of the stock ones:
actions_list (buttons above the changelist), actions_detail (buttons on the change form)
and the template hooks list_before_template, list_after_template,
change_form_before_template, change_form_after_template,
change_form_outer_before_template, change_form_outer_after_template. An entry of
actions_list / actions_detail is a method name or a group
{"title": ..., "icon": ..., "items": [names]} shown as a dropdown.
Field Types
All field configs are Pydantic models in the discriminated union FieldConfigType (16 types), keyed on ui_widget. The list below is the real field set; see Field Types for usage.
FieldConfig (Base)
Fields every field config has:
class FieldConfig(BaseModel):
name: str # Field name (required)
title: str | None = None # Column title
ui_widget: str # Fixed per subclass, selects the renderer
header: bool = False # Render as the row header (first cell)
ordering: str | None = None # Sort column / expression
empty_value: str = "—" # Shown when the value is None
icon: str | None = None # Material icon
css_class: str | None = None
tooltip: str | None = NoneSubclass fields
| Class | ui_widget | Own fields (defaults) |
|---|---|---|
BadgeField | badge | variant (None; primary, secondary, success, danger, warning, info), label_map (value to variant) |
BooleanField | boolean | true_icon ("check_circle"), false_icon ("cancel") |
CurrencyField | currency | currency (None), currency_field, secondary_field, secondary_currency ("USD"), precision (2), show_sign (False), thousand_separator (True) |
DateTimeField | datetime_relative | datetime_format (None), show_relative (True), use_local_tz (True) |
DecimalField | decimal | decimal_places (2), prefix, suffix, show_sign, thousand_separator |
ForeignKeyField | foreignkey | display_field (required), link_field ("id"), link_to_admin (True), link_icon, link_target ("_self"), subtitle_field, subtitle_fields, subtitle_template, subtitle_separator, show_null_as_empty, null_display, subtitle_css_class |
ImageField | image | width, height, max_width ("200px"), max_height, border_radius, caption, caption_field, caption_template, alt_text |
ImagePreviewField | image_preview | thumbnail_max_width (200), thumbnail_max_height (150), border_radius (8), show_info, show_filename, show_dimensions, show_size, show_format, zoom_enabled, zoom_min, zoom_max, zoom_step, pan_enabled, caption*, alt_text, url_method, fallback_field, condition_field, condition_value, fallback_text, fallback_badge_variant |
LinkField | link | link_field (required), link_icon ("open_in_new"), link_target ("_blank"), static_text, subtitle_field, subtitle_fields, subtitle_template, subtitle_separator, subtitle_css_class |
MarkdownField | markdown | collapsible (True), default_open (False), max_height ("500px"), full_width (True), source_file, source_field, enable_plugins (True), header_icon |
MoneyFieldDisplay | money_field | currency_field, default_currency ("USD"), target_field, target_currency ("USD"), rate_field, rate_at_field, show_rate (True), precision (2), compact (True), currency_symbols |
ShortUUIDField | short_uuid | length (8), copy_on_click (True), show_full_on_hover (True), is_link (False) |
StackedField | stacked | rows (required; RowItem or lists of them), gap, inline_gap, align (left, center, right), min_width, max_width ("300px") |
StatusBadgesField | status_badges | badge_rules (required; list of BadgeRule), empty_text, empty_variant, separator |
TextField | text | truncate (chars, None), monospace, nowrap (True), max_width ("300px"), show_tooltip (True) |
UserField | user_avatar or user_simple | show_email (True), show_avatar (True), avatar_size (32) |
Configuration Classes
FieldsetConfig
Fieldset configuration.
class FieldsetConfig(BaseModel):
title: str # Fieldset title
fields: List[str] # Field names
collapsed: bool = False # Start collapsed
description: str | None = None # Optional description
def to_django_fieldset(self) -> Tuple:
"""Convert to Django fieldset format."""ActionConfig
Action configuration for admin actions.
class ActionConfig(BaseModel):
name: str # Action name
description: str # Display description
action_type: Literal["bulk", "changelist"] = "bulk" # Action type
handler: Union[str, Callable] # Action function or import path
variant: str = "default" # Button variant
icon: Optional[str] = None # Material icon name
url_path: Optional[str] = None # Custom URL path (changelist actions)
confirmation: bool = False # Ask before running
method: Literal["post", "get"] = "post" # Changelist actions: POST form or link
permissions: List[str] = [] # Required permissions
def get_handler_function(self) -> Callable:
"""Import and return the handler function."""Parameters:
- name (str): Action function name
- description (str): Display text shown in UI
- action_type (“bulk” | “changelist”):
"bulk"- Traditional bulk action (requires selection, dropdown menu)"changelist"- Button above listing (no selection required)
- handler (str | Callable): Action handler function or Python import path
- variant (str): Button color variant (default, success, warning, danger, primary, info)
- icon (str | None): Material Design icon name
- url_path (str | None): Custom URL path for changelist actions
- confirmation (bool): Ask before running. Bulk: a confirmation page, then a second POST with
post=yes. Changelist button: the browser’sconfirm() - method (“post” | “get”): Changelist actions only.
"post"(default): a POST form with the CSRF token, GET answers 405."get": a link, for a handler that renders its own page or form - permissions (list[str]): Required permission codenames
Handler Signatures:
- Bulk:
handler(modeladmin, request, queryset) -> None - Changelist:
handler(modeladmin, request) -> HttpResponse
Decorators
@action
Marks a ModelAdmin method as an action: a bulk action (actions), a changelist button
(actions_list, signature (self, request)) or a change form button
(actions_detail, signature (self, request, object_id)).
from django_cfg.modules.django_admin import action
@action(
description: str | None = None, # Label in the dropdown or on the button
permissions: list[str] | None = None, # "change" → has_change_permission; "app.codename" → has_perm
url_path: str | None = None, # Button URL segment (default: method name)
icon: str | None = None, # Material Symbols name
variant: str | None = None, # default, primary, success, info, warning, danger
attrs: dict | None = None, # Extra HTML attributes of the button
confirm: str | None = None, # Confirmation text
method: str = "post", # Buttons: "post" (form + CSRF, GET → 405) or "get" (a link)
)
def method_name(self, request, ...): ...class ServerAdmin(PydanticAdmin):
config = server_config
actions_detail = ["rebuild", "edit_names"]
@action(description="Rebuild", url_path="rebuild", permissions=["change"])
def rebuild(self, request, object_id):
... # runs on POST only
@action(description="Edit names", url_path="names", method="get")
def edit_names(self, request, object_id):
form = NamesForm(request.POST or None)
... # a page with its own form: handles GET and its own POSTA failing permission check hides the button and the URL answers 403. With confirm, a
button asks with confirm() before the POST; a bulk action shows a confirmation page and
runs on the second POST (post=yes, as Django’s delete_selected).
@computed_field
Decorator for custom display methods.
from django_cfg.modules.django_admin import computed_field
@computed_field(
short_description: str, # Column header
ordering: str | None = None, # Sort field
boolean: bool = False, # Boolean display
empty_value: str = "—" # When None
)
def method_name(self, obj): ...@annotated_field
Decorator for annotated values.
from django_cfg.modules.django_admin import annotated_field
@annotated_field(
short_description: str, # Column header
annotation_name: str, # Annotation key
ordering: str | None = None, # Sort field (defaults to annotation_name)
empty_value: str = "—" # When None
)
def method_name(self, obj): ...HTML Utilities
HTML utilities provide rich formatting for readonly fields and custom display methods in Django Admin.
Using in Admin Classes
The primary way to use HTML utilities is through self.html.* in admin methods:
from django_cfg.modules.django_admin.base import PydanticAdmin
class MyAdmin(PydanticAdmin):
def my_readonly_field(self, obj):
"""Custom display using self.html utilities."""
return self.html.inline([
self.html.badge(obj.status, variant="success"),
self.html.span(f"Items: {obj.count}", "font-semibold"),
])
def another_display(self, obj):
"""Format numbers and UUIDs."""
return self.html.inline([
self.html.number(obj.price, precision=2, prefix="$"),
self.html.uuid_short(obj.id, length=6),
])All methods available on self.html:
- Basic:
icon(),span(),text(),div(),link(),empty() - Code:
code(),code_block() - Badges:
badge() - Composition:
inline(),stacked(),icon_text(),colored_text(),header() - Formatting:
number(),uuid_short(),truncate() - Key-Value:
key_value(),breakdown(),divider(),key_value_list() - Progress:
segment(),progress_bar() - Markdown:
markdown(),markdown_docs()
Module Structure (Advanced)
For advanced use cases outside admin classes, you can import modules directly:
from django_cfg.modules.django_admin.utils import (
BaseElements, # Basic HTML: icon, span, text, div, link, empty
CodeElements, # Code blocks: code, code_block
BadgeElements, # Badges: badge
CompositionElements, # Composition: inline, icon_text, colored_text, header
FormattingElements, # Formatting: number, uuid_short
KeyValueElements, # Key-value: key_value, breakdown, divider
ProgressElements, # Progress: segment, progress_bar
MarkdownIntegration, # Markdown: markdown, markdown_docs
)BaseElements
Basic HTML building blocks.
icon()
BaseElements.icon(
icon_name: str,
size: str = "xs", # xs, sm, base, lg, xl
css_class: str = ""
) -> SafeStringspan()
BaseElements.span(
text: Any,
css_class: str = ""
) -> SafeStringtext()
Styled text with semantic variants.
BaseElements.text(
content: Any,
variant: str | None = None, # success, warning, danger, info, primary
size: str | None = None, # xs, sm, base, lg, xl, 2xl
weight: str | None = None, # normal, medium, semibold, bold
muted: bool = False
) -> SafeStringdiv()
BaseElements.div(
content: Any,
css_class: str = ""
) -> SafeStringlink()
BaseElements.link(
url: str,
text: str,
css_class: str = "",
target: str = "" # _blank, _self, etc.
) -> SafeStringempty()
BaseElements.empty(
text: str = "—"
) -> SafeStringCodeElements
Code display utilities.
code()
Inline code block.
CodeElements.code(
text: Any,
css_class: str = ""
) -> SafeStringcode_block()
Multi-line code block with syntax highlighting support.
CodeElements.code_block(
text: Any,
language: str | None = None, # json, python, bash, etc.
max_height: str | None = None, # "400px", "20rem"
variant: str = "default" # default, warning, danger, success, info
) -> SafeStringBadgeElements
Badge rendering.
badge()
BadgeElements.badge(
text: Any,
variant: str = "primary", # primary, success, warning, danger, info, secondary
icon: str | None = None # Material icon name
) -> SafeStringCompositionElements
Element composition utilities.
inline()
Join items with separator, preserving SafeString HTML.
CompositionElements.inline(
*items,
separator: str = " | ",
size: str = "small", # small, medium, large
css_class: str = ""
) -> SafeStringUsage:
# Join multiple elements with separator
def stats_display(self, obj):
return CompositionElements.inline(
CompositionElements.icon_text(Icons.EDIT, obj.posts_count),
CompositionElements.icon_text(Icons.CHAT, obj.comments_count),
separator=" | "
)stacked()
Stack items vertically (one below another). Useful for multi-line display in computed fields.
CompositionElements.stacked(
items: list,
css_class: str = ""
) -> SafeStringUsage:
# Multi-line pricing display
def pricing_info(self, obj):
return self.html.stacked([
self.html.text(f"In: ${obj.input_price}", weight="semibold"),
self.html.text(f"Out: ${obj.output_price}", muted=True),
])
# Status with details
def status_display(self, obj):
return self.html.stacked([
self.html.badge(obj.status, variant="success"),
self.html.text(f"Updated: {obj.updated_at}", muted=True, size="xs"),
])icon_text()
Icon with text and optional color.
CompositionElements.icon_text(
icon_or_text: str | Any,
text: Any = None,
icon_size: str = "xs",
separator: str = " ",
color: str = None # success, warning, danger, info, secondary, primary
) -> SafeStringExamples:
# Icon with text
self.html.icon_text(Icons.EDIT, 5)
# Icon with text and color
self.html.icon_text(Icons.CHECK_CIRCLE, "Yes", color="success")
self.html.icon_text(Icons.CANCEL, "No", color="secondary")
# Just text (no icon)
self.html.icon_text("Active")colored_text()
Colored text without icon.
CompositionElements.colored_text(
text: Any,
color: str = None # success, warning, danger, info, secondary, primary
) -> SafeStringExamples:
# Time ago with color based on freshness
if age < 120:
self.html.colored_text("2 minutes ago", "success")
elif age < 300:
self.html.colored_text("5 minutes ago", "warning")
else:
self.html.colored_text("10 minutes ago", "danger")Available colors:
success- Green (positive states)warning- Yellow (attention needed)danger/error- Red (critical states)info- Blue (informational)secondary- Gray (neutral)primary- Indigo (brand color)
header()
Header with avatar, title, and subtitle.
CompositionElements.header(
title: str,
subtitle: str | None = None,
initials: str | None = None,
avatar_variant: str = "primary"
) -> SafeStringFormattingElements
Number and UUID formatting.
number()
Smart number formatting with precision handling.
FormattingElements.number(
value: Any,
precision: int = 8,
thousands_separator: bool = True,
strip_zeros: bool = True,
min_threshold: float | None = None,
compact: bool = False, # Use K/M/B/T suffixes
prefix: str = "",
suffix: str = "",
css_class: str = ""
) -> SafeStringUsage:
# Currency
FormattingElements.number(1234.56, precision=2, prefix="$") # "$1,234.56"
# Compact notation
FormattingElements.number(1500000, compact=True, prefix="$") # "$1.5M"
# Crypto balance
FormattingElements.number(0.00012345, precision=8) # "0.00012345"uuid_short()
Shorten UUID with tooltip.
FormattingElements.uuid_short(
uuid_value: Any,
length: int = 6, # Number of characters to show
show_tooltip: bool = True # Show full UUID on hover
) -> SafeStringtruncate()
Truncate text to specified length with optional tooltip.
FormattingElements.truncate(
text: str,
length: int = 100, # Maximum length (default: 100)
suffix: str = "...", # Text to append when truncated
show_tooltip: bool = True # Show full text on hover (default: True)
) -> SafeStringUsage:
# Truncate long message
self.html.truncate("Long message text here", length=50)
# Custom suffix
self.html.truncate(obj.description, length=80, suffix="…")
# No tooltip
self.html.truncate(obj.message_text, show_tooltip=False)Returns:
- If text is shorter than limit: returns text as-is
- If text is longer: truncates and adds suffix
- With tooltip: shows full text on hover
KeyValueElements
Key-value pair utilities.
key_value()
Single key-value pair.
KeyValueElements.key_value(
key: str,
value: Any,
icon: str | None = None,
indent: bool = False,
divider: bool = False,
value_variant: str | None = None,
value_size: str | None = None
) -> SafeStringbreakdown()
Combine multiple key-value pairs.
KeyValueElements.breakdown(*items) -> SafeStringdivider()
KeyValueElements.divider(css_class: str = "my-2") -> SafeStringProgressElements
Progress bar utilities.
segment()
Create progress bar segment.
ProgressElements.segment(
percentage: float,
variant: str = 'primary',
label: str = ''
) -> dictprogress_bar()
Multi-segment progress bar.
ProgressElements.progress_bar(
*segments,
width: str = "w-full max-w-xs",
height: str = "h-6",
show_labels: bool = True,
rounded: bool = True
) -> SafeStringUsage:
ProgressElements.progress_bar(
ProgressElements.segment(60, variant='success', label='Available'),
ProgressElements.segment(40, variant='warning', label='Locked')
)MarkdownIntegration
Markdown rendering integration.
markdown()
Render markdown text.
MarkdownIntegration.markdown(
text: str,
css_class: str = "",
max_height: str | None = None,
enable_plugins: bool = True
) -> SafeStringmarkdown_docs()
Render markdown documentation with collapsible UI.
MarkdownIntegration.markdown_docs(
content: str | Path,
collapsible: bool = True,
title: str = "Documentation",
icon: str = "description",
max_height: str | None = "500px",
enable_plugins: bool = True,
default_open: bool = False
) -> SafeStringDisplay Utilities
UserDisplay
from django_cfg.modules.django_admin.utils.displays import UserDisplay
from django_cfg.modules.django_admin.models.display_models import UserDisplayConfig
# With avatar
UserDisplay.with_avatar(
user: User,
config: UserDisplayConfig | None = None
) -> List[str] # [name, email, initials, avatar_data]
# Simple display
UserDisplay.simple(
user: User,
config: UserDisplayConfig | None = None
) -> SafeStringUserDisplayConfig:
class UserDisplayConfig(BaseModel):
show_avatar: bool = True
show_email: bool = False
avatar_size: str = "md" # sm, md, lgMoneyDisplay
from django_cfg.modules.django_admin.utils.displays import MoneyDisplay
from django_cfg.modules.django_admin.models.display_models import MoneyDisplayConfig
# Format amount
MoneyDisplay.amount(
amount: Decimal | float | int,
config: MoneyDisplayConfig | None = None
) -> SafeStringMoneyDisplayConfig:
class MoneyDisplayConfig(BaseModel):
currency: str = "USD"
decimal_places: int = 2
thousand_separator: bool = True
show_currency_symbol: bool = True
show_sign: bool = False
smart_decimal_places: bool = False # Auto-adjust based on amount
rate_mode: bool = False # Special formatting for ratesDateTimeDisplay
from django_cfg.modules.django_admin.utils.displays import DateTimeDisplay
from django_cfg.modules.django_admin.models.display_models import DateTimeDisplayConfig
# Relative time
DateTimeDisplay.relative(
dt: datetime,
config: DateTimeDisplayConfig | None = None
) -> SafeString
# Compact display
DateTimeDisplay.compact(
dt: datetime,
config: DateTimeDisplayConfig | None = None
) -> SafeStringDateTimeDisplayConfig:
class DateTimeDisplayConfig(BaseModel):
datetime_format: str = "%Y-%m-%d %H:%M"
show_relative: bool = FalseIcons
Icons Class
2234+ Material Design icons with autocomplete.
from django_cfg import Icons
# Common icons
Icons.CHECK_CIRCLE
Icons.CANCEL
Icons.EDIT
Icons.DELETE
Icons.VISIBILITY
Icons.SETTINGS
Icons.PERSON
Icons.EMAIL
Icons.BUSINESS
Icons.SHOPPING_CART
Icons.RECEIPT
Icons.CURRENCY_BITCOIN
Icons.ADMIN_PANEL_SETTINGS
Icons.PRIORITY_HIGH
Icons.ARTICLE
Icons.CATEGORY
Icons.SCHEDULE
Icons.ERROR
Icons.WARNING
Icons.MOUSE
Icons.API
Icons.PACKAGE
Icons.HISTORY
Icons.SUPPORT_AGENT
Icons.SMART_TOY
Icons.CAMPAIGN
Icons.NEW_RELEASES
Icons.STAR
Icons.LOCAL_OFFER
Icons.ARROW_UPWARD
Icons.ARROW_DOWNWARD
Icons.REMOVE
Icons.SHOPPING_BAG
# ... 2200+ more icons with full IDE autocompleteIconCategories
Group icons by category for easier discovery.
from django_cfg import IconCategories
IconCategories.ACTIONS # Common action icons
IconCategories.CONTENT # Content-related icons
IconCategories.COMMUNICATION # Communication icons
IconCategories.SOCIAL # Social icons
IconCategories.PLACES # Location icons
IconCategories.DEVICE # Device iconsWidget Registry
Internal registry for widget renderers (advanced usage).
from django_cfg.modules.django_admin import WidgetRegistry
# Register custom widget
WidgetRegistry.register("my_widget", my_render_function)
# Render widget
WidgetRegistry.render("badge", obj, field_name, config)Pydantic Models
BadgeVariant
from django_cfg.modules.django_admin import BadgeVariant
class BadgeVariant(str, Enum):
PRIMARY = "primary"
SECONDARY = "secondary"
SUCCESS = "success"
DANGER = "danger"
WARNING = "warning"
INFO = "info"BadgeConfig
from django_cfg.modules.django_admin import BadgeConfig
class BadgeConfig(BaseModel):
variant: BadgeVariant = BadgeVariant.PRIMARY
icon: str | None = None
css_classes: List[str] = []FieldConfigType
Discriminated union of all 16 field config types. Use for type narrowing in custom code.
from django_cfg.modules.django_admin import FieldConfigType
# FieldConfigType is a Union of all concrete FieldConfig subclasses,
# discriminated on the `ui_widget` literal field.
# Use it as the type annotation for display_fields entries:
display_fields: List[FieldConfigType] = [
BadgeField(name="status"),
CurrencyField(name="price"),
# ... any of the 16 field config types
]DjangoFieldsets
TypeAlias for Django’s native fieldsets format.
from django_cfg.modules.django_admin import DjangoFieldsets
DjangoFieldsets = tuple[tuple[str | None, dict[str, Any]], ...]
# Example value:
fieldsets: DjangoFieldsets = (
(None, {"fields": ["name", "email"]}),
("Advanced", {"fields": ["api_key"], "classes": ["collapse"]}),
)FilterSpec
TypeAlias for list_filter entries. Accepts a plain string field name, a filter class,
a (field_name, filter_class) tuple, or a FilterConfig instance.
from django_cfg.modules.django_admin import FilterSpec
FilterSpec = str | type | tuple[str, type] | FilterConfigFilterConfig
Pydantic model for declarative filter configuration. Converts to the Django-compatible
list_filter entry format under the hood.
from django_cfg.modules.django_admin import FilterConfig
FilterConfig(
field: str, # Model field name
type: FilterType | None = None, # One of 17 preset filter types
filter_class: type | None = None, # Raw Django filter class (bypasses type)
title: str | None = None, # Sidebar label (SimpleListFilter types only)
)type must be set unless filter_class is provided.
from django_cfg.modules.django_admin import AdminConfig, FilterConfig
config = AdminConfig(
model=Order,
list_filter=[
FilterConfig(field='status', type='choices_dropdown'),
FilterConfig(field='created_at', type='range_date'),
FilterConfig(field='amount', type='range_numeric'),
FilterConfig(field='customer', type='autocomplete'),
FilterConfig(field='is_active', type='boolean'),
# Raw entries still work alongside FilterConfig:
'currency',
MyCustomFilter,
],
)See Filters Guide for all type values and usage patterns.
FilterType
Literal type with all valid FilterConfig.type values:
FilterType = Literal[
# FieldListFilter-based (bound to model field)
"choices_dropdown", # CharField/IntegerField with choices, a <select>
"choices_dropdown_multiple", # fallback: same, single choice
"choices_checkbox", # fallback: Django's choices link list
"choices_radio", # Django's choices link list
"boolean", # BooleanField: All / Yes / No
"related_dropdown", # ForeignKey, a <select>
"related_dropdown_multiple", # fallback: same, single choice
"related_checkbox", # fallback: Django's related link list
"autocomplete", # ForeignKey with a select2 search box (needs related search_fields)
"autocomplete_multiple", # fallback: same, single choice
"range_numeric", # Numeric from/to (rangefilter)
"slider", # fallback: numeric from/to, no slider
"range_date", # DateField from/to (rangefilter)
"range_datetime", # DateTimeField from/to (rangefilter)
"text", # icontains text box
# SimpleListFilter-based (dynamic subclass — needs custom queryset logic)
"dropdown", # Single dropdown
"dropdown_multiple", # fallback: single dropdown
]A type marked “fallback” has no exact stock equivalent: the nearest filter is used and a
FilterFallbackWarning (django_cfg.modules.django_admin.config.filter_config) says so.
Complete Import Example
from django.contrib import admin
from django.db.models import Count
# Core
from django_cfg.modules.django_admin import (
AdminConfig,
FieldsetConfig,
ActionConfig,
)
# Types and type aliases
from django_cfg.modules.django_admin import (
FieldConfigType, # Discriminated union of all 16 field config types
DjangoFieldsets, # TypeAlias: tuple[tuple[str | None, dict[str, Any]], ...]
FilterSpec, # TypeAlias: str | type | tuple[str, type] | FilterConfig
FilterConfig, # Pydantic model for declarative list_filter entries
FilterType, # Literal of all 17 filter type keys
)
# Field types
from django_cfg.modules.django_admin import (
BadgeField,
BooleanField,
CurrencyField,
DateTimeField,
ShortUUIDField,
TextField,
UserField,
)
# Icons
from django_cfg import Icons
# Decorators
from django_cfg.modules.django_admin.utils import (
computed_field,
annotated_field,
badge_field,
currency_field,
)
# HTML utilities (new modular structure)
from django_cfg.modules.django_admin.utils import (
BaseElements, # Basic HTML elements
CodeElements, # Code blocks
BadgeElements, # Badges
CompositionElements, # Element composition
FormattingElements, # Number/UUID formatting
KeyValueElements, # Key-value pairs
ProgressElements, # Progress bars
MarkdownIntegration, # Markdown rendering
)
# Display utilities
from django_cfg.modules.django_admin.utils import (
UserDisplay,
MoneyDisplay,
DateTimeDisplay,
StatusBadge,
ProgressBadge,
CounterBadge,
MarkdownRenderer,
)
# Display configs
from django_cfg.modules.django_admin.models.display_models import (
UserDisplayConfig,
MoneyDisplayConfig,
DateTimeDisplayConfig,
)
# Badge configs
from django_cfg.modules.django_admin.models.badge_models import (
StatusBadgeConfig,
BadgeConfig,
)
# Base admin
from django_cfg.modules.django_admin.base import PydanticAdminVersion
Current version: 2.0.0
Next Steps
- Overview - Learn the philosophy
- Quick Start - Get started in 5 minutes
- Configuration - Configuration guide
- Filters - Complete guide to filters
- Examples - Real-world examples