Row and list actions
Row actions sit in the last changelist column. List actions sit above the table. Both are declarative and permission-aware. Field tables: Options catalog.
Row actions
from django.utils.translation import gettext_lazy as _
from django_chassis.enums import ButtonColor, RowActionDisplay, RowActionType
from django_chassis.options import RowActionOption, RowActionsOption
RowActionsOption(
actions=[
RowActionOption(
action_type=RowActionType.VIEW,
label=_('Open'),
color=ButtonColor.PRIMARY,
icon_class='fa-solid fa-arrow-right',
display=RowActionDisplay.ICON,
),
RowActionOption(
action_type=RowActionType.CHANGE,
label=_('Edit'),
color=ButtonColor.SECONDARY,
icon_class='fa-solid fa-pen',
permission='change',
),
RowActionOption(
action_type=RowActionType.DELETE,
label=_('Delete'),
color=ButtonColor.DANGER,
icon_class='fa-solid fa-trash',
permission='delete',
),
RowActionOption(
action_type=RowActionType.HISTORY,
label=_('History'),
color=ButtonColor.SECONDARY,
icon_class='fa-solid fa-clock-rotate-left',
),
]
)
RowActionsOption() without arguments adds a single view button.
RowActionOption
| Parameter | Type | Default |
|---|---|---|
action_type | RowActionType | required |
label | localized string | required |
color | ButtonColor | required |
icon_class | Font Awesome class | required |
display | ICON or BUTTON | ICON |
permission | codename or None | inferred from type when possible |
RowActionType values: view, change, delete, history.
Hidden actions stay hidden. A missing permission hides the button; it does not show a disabled control.
List actions
Top-of-list links to named URLs.
from django_chassis.options import ListActionOption, ListActionsOption
ListActionsOption(
actions=[
ListActionOption(
url_name='admin:catalog_book_changelist',
label='All books',
color=ButtonColor.PRIMARY,
icon_class='fa-solid fa-list',
permission='view',
condition_method='can_show_all_books',
)
]
)
| Parameter | Type | Default |
|---|---|---|
url_name | Django URL name | required |
label | localized string | required |
color | ButtonColor | PRIMARY |
icon_class | Font Awesome class | '' |
permission | codename or None | None |
condition_method | method name on the ModelAdmin | None |
condition_method must name a @classmethod shaped as
(cls, request) -> bool. If it returns False, the action is omitted.
Object actions
Per-object methods use @object_action and ObjectActionsOption. See
Object actions.