Skip to main content

ModelAdmin

Added in 1.0.1

ChassisAdminMixin is the ModelAdmin entry point. Put it first in the MRO. Attach capabilities through options.

from django.contrib.admin import ModelAdmin

from django_chassis.mixins import ChassisAdminMixin
from django_chassis.options import RowActionsOption, SearchOption, Settings


class BookAdmin(ChassisAdminMixin, ModelAdmin):
chassis_settings = Settings(search_collapsed=True, allow_standard_add=True)
options = [SearchOption(fields=['title']), RowActionsOption()]

MRO​

class BookAdmin(ChassisAdminMixin, ModelAdmin): # correct
...


class BookAdmin(ModelAdmin, ChassisAdminMixin): # wrong — hooks will not wrap super()
...

The same rule applies to ReadOnlyAdminMixin and NoDeleteAdminMixin: they must sit where their has_*_permission overrides still run.

Change-form anatomy​

Changed in 1.0.7

Pass _return_url in the change-form query string when the Back button should return to another internal page. Chassis accepts relative and same-host URLs, rejects external hosts, and ignores a return URL that points back to the same change form.

Template: admin/chassis/change_form.html (extends admin/change_form.html).

┌─ breadcrumbs ─────────────────────────────────────────────┐
│ Dashboard › Section › Model › object │
├─ toolbar (`page_actions`) ────────────────────────────────┤
│ [@object_action buttons…] [Django history / …] │
├─ Django fieldsets / inlines ──────────────────────────────┤
│ Pretty JSON / decimal widgets / date masks │
│ RelatedCollectionsOption inputs with add/delete controls │
├─ related entities (`after_field_sets`) ───────────────────┤
│ One fieldset per RelatedEntityOption (paginated table) │
├─ submit row ──────────────────────────────────────────────┤
│ [Save] [Back] [Delete] │
└───────────────────────────────────────────────────────────┘

The submit row uses the shared right-aligned action panel and Back button. Required fields receive a consistent red marker, while required confirmation checkboxes use full-width labels and appear after other fields. Validation errors are summarized above the form in the common danger alert.

Object actions require ObjectActionsOption plus @object_action on the methods. Related tables require RelatedEntitiesOption. See Object actions and Related entities.

Use the action column in the changelist to open a record.

How get_chassis_option resolves​

  1. Walk self.options and return the first instance of the requested type.
  2. If none, walk ChassisAdminMixin.options, which contains RowActionsOption() by default.
  3. Composite things (several FK groups, several row actions) live inside one option object.

There is no merging of two SearchOption instances. The local one wins.

options​

options is a list of frozen dataclasses. Do not rename this attribute.

Full field tables, validation, and UI regions: Options catalog.

AdminOption is the union of:

  • SearchOption
  • FiltersOption
  • DateHierarchyOption
  • FieldTabsOption
  • ForeignKeyTabsOption
  • BadgeFieldsOption
  • CopyableFieldsOption
  • DecimalAmountOption
  • RelatedFieldsOption
  • RelatedCollectionsOption
  • PrettyJsonOption
  • RowActionsOption
  • ListActionsOption
  • ObjectActionsOption
  • RelatedEntitiesOption
  • ImportOption
  • ExportOption
  • EntityPickerOption
  • FieldHistoryOption
  • FormLayoutOption
  • PageHeaderOption

The mixin defaults to [RowActionsOption()]. Supply a local RowActionsOption to customize the last-column buttons.

Settings​

Not an option. Assigned to chassis_settings.

ParameterDefaultPurpose
search_collapsedTrueStart with the search fieldset collapsed
date_hierarchy_collapsedTrueCollapse the date hierarchy fieldset
filters_collapsedTrueCollapse the filters fieldset
allow_standard_addTrueWhen False, has_add_permission() is False
warn_unsaved_changesFalseWarn when leaving a modified form. FormLayoutOption also enables this. Added in 1.0.23

Other mixin attributes​

AttributeDefaultPurpose
change_list_templateadmin/chassis/change_list.htmlChassis changelist
change_form_templateadmin/chassis/change_form.htmlChassis change form

Companion mixins​

  • ReadOnlyAdminMixin — deny add, change, and delete
  • NoDeleteAdminMixin — deny delete

Put the denial mixin before ChassisAdminMixin when its has_*_permission overrides must win:

class LogAdmin(ReadOnlyAdminMixin, ChassisAdminMixin, ModelAdmin):
options = [SearchOption(fields=['message'])]

System checks​

ChassisAdminMixin runs checks for action permissions and export lookups. Failures show up as Django system checks, not silent template gaps.

See also​

Titles and form blocks​

Added in 1.0.23

Use PageHeaderOption and FormLayoutOption in ModelAdmin.options. This example assumes a registered catalog.Product with the named fields.

from django_chassis.options import (
FormBlockOption,
FormLayoutOption,
PageBreadcrumbOption,
PageHeaderOption,
RowActionsOption
)

options = [
PageHeaderOption(
list_title='Catalog',
add_title='Add product',
change_title='Edit product',
view_title='Product details',
breadcrumbs=[
PageBreadcrumbOption('Catalog', 'project_admin:catalog_product_changelist'),
PageBreadcrumbOption('Products')
]
),
FormLayoutOption(blocks=[
FormBlockOption(title='Details', fields=[('name', 'code'), 'description']),
FormBlockOption(title='Status', fields=[('active', 'priority')])
]),
RowActionsOption(quick_view=True)
]
ParameterBehavior
titleFallback title for modes without their own title.
list_title, add_title, change_title, view_titleOverride the respective page title.
descriptionOptional text below the heading.
breadcrumbsNone uses Django's trail. An empty list hides it. Omit url_name for a text-only crumb. Adjust project_admin to your mounted site name.
FormBlockOption.fieldsLists field names. Group names in a tuple for one row. Field names must be unique across blocks.
span, description, collapsed, show_on_addControl the block width (1–12, default 6), help text, initial collapse and availability on add forms.

Blocks keep permissions and widgets from Django Admin. Columns stack on narrow screens. Fields outside blocks retain their original fieldsets. A layout turns on unsaved-change warnings. Without a layout, use chassis_settings = Settings(warn_unsaved_changes=True).

Standard scalar fields use a responsive 40em width. Customize it using the --chassis-field-width CSS variable.

Quick inspection​

Added in 1.0.23

RowActionsOption(quick_view=True) adds a read-only preview in the Actions column. Chassis supplies separate edit and delete actions when allowed. Keep at least one action in RowActionsOption.actions to enable the preview. Its GET URL is named <site-name>:<app_label>_<model_name>_inspect and takes the quoted object ID. The endpoint checks visibility on the actual object, honors form exclusions, and masks recognized secret inputs and CopyableFieldsOption.masked_fields. Exclude any additional sensitive fields from the form, or declare their masking explicitly.

Compare the last two field snapshots​

Added in 1.0.23

Use FieldHistoryOption on a model that already has a compatible django-simple-history snapshot manager. If you are adding the manager to your model, configure that library and apply the generated model migration. Keep Chassis first in the admin class's inheritance order.

from django.contrib.admin import ModelAdmin

from django_chassis.mixins import ChassisAdminMixin
from django_chassis.options import FieldHistoryOption


class ProductAdmin(ChassisAdminMixin, ModelAdmin):
options = [FieldHistoryOption(fields=['name', 'description', 'active'], manager_name='history')]

Save two successive versions of a product and open History. Chassis reads the newest two snapshots. The comparison lists changed, visible allowed fields, plus the change time and author when available. Text and JSON can show a diff. With fewer than two snapshots or a missing manager the comparison is empty. Change manager_name if your project mounted HistoricalRecords under a different name.

Supply an explicit allowlist of safe fields. Hidden fields, relations and recognized secret fields are skipped. The comparison only reads existing snapshots. If you supply your own object_history_template, render the field_history context value with {% chassis_component field_history %} and include the media used by admin/chassis/object_history.html.