Object actions
Object actions are ModelAdmin methods that run against one object. Register
them with @object_action and list their names in ObjectActionsOption.
Actions can include an icon from the Font Awesome bundle shipped by Chassis.
Added in 1.0.15Set opens_modal=True to load the action response through the shared Chassis
modal client. The action keeps the same compact colored button as every other
object action, and its href remains available as an accessible fallback.
from django.contrib import messages
from django.http import HttpRequest, HttpResponseRedirect
from django.utils.translation import gettext_lazy as _
from django_chassis.decorators import object_action
from django_chassis.enums import ButtonColor
from django_chassis.mixins import ChassisAdminMixin
from django_chassis.options import ObjectActionsDropdownOption, ObjectActionsOption
class BookAdmin(ChassisAdminMixin, ModelAdmin):
options = [
ObjectActionsOption(
actions=['publish'],
dropdown=ObjectActionsDropdownOption(actions=['archive'])
)
]
@object_action(
description=_('Publish'),
permission='change',
confirmation=_('Publish this book?'),
color=ButtonColor.SUCCESS,
icon_class='fa-solid fa-bullhorn',
opens_modal=True
)
def publish(self, request: HttpRequest, obj: Book) -> HttpResponseRedirect | None:
obj.publish()
messages.success(request, _('Published.'))
return None
Decorator
@object_action(
description,
*,
permission=None,
confirmation=None,
color=ButtonColor.PRIMARY,
icon_class=None,
opens_modal=False,
condition=None,
condition_method=None,
)
| Parameter | Purpose |
|---|---|
description | Button label (lazy strings allowed) |
permission | view / add / change / delete or a custom codename |
confirmation | If set, Chassis shows a confirm form before calling the method |
color | ButtonColor |
icon_class | Optional Font Awesome CSS classes rendered before the label |
opens_modal | Load the action response in the shared Chassis modal |
condition | callable(admin, request, obj) -> bool |
condition_method | Name of a @classmethod invoked as (request, obj) |
condition and condition_method are mutually exclusive.
The method signature is (self, request, obj). Return HttpResponse to
redirect or render, or None to stay on the object page.
Route (ModelAdmin):
{admin}/{app}/{model}/{object_id}/actions/{action_name}/
URL name: {app}_{model}_object_action. Permission and condition are
checked again on that request, not only when the button is rendered.
AdminObjectPage uses the same decorator on a non-model card — see
Custom pages.
ObjectActionsOption
ObjectActionsOption(
actions=['publish'],
dropdown=ObjectActionsDropdownOption(actions=['archive'])
)
Only listed names are exposed. An undecorated method in the list fails configuration.
Added in 1.0.7dropdown explicitly places its action names under the primary
Additional actions menu. Names must be unique across actions and
dropdown.actions; an empty dropdown is invalid. Independently of explicit
grouping, Chassis automatically renders six or more visible toolbar actions as
one dropdown, while five or fewer remain individual buttons.
Confirmation
When confirmation is set, Chassis renders
admin/chassis/confirmed_action.html with ConfirmedActionForm. The method
runs only after POST confirm.
Object-action templates that extend
admin/object_actions/base_action_view.html now use the shared Chassis page
shell and place their content in the object_action_content block. The shell
provides compact form, information-table, warning, and action-button styling.
Action pages use the full content width. Their lower action panel is aligned to
the right and includes the shared Back button; validation errors are summarized
in the common danger alert, and required confirmation checkboxes are rendered
after the other fields.