Skip to main content

Row and list actions

Added in 1.0.1

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

ParameterTypeDefault
action_typeRowActionTyperequired
labellocalized stringrequired
colorButtonColorrequired
icon_classFont Awesome classrequired
displayICON or BUTTONICON
permissioncodename or Noneinferred 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',
)
]
)
ParameterTypeDefault
url_nameDjango URL namerequired
labellocalized stringrequired
colorButtonColorPRIMARY
icon_classFont Awesome class''
permissioncodename or NoneNone
condition_methodmethod name on the ModelAdminNone

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.

See also