Skip to main content

Tables

Added in 1.0.1

TableOption is the generic table contract. Related entities, information pages, and history-style views reuse it. Full field tables: Options catalog.

from django_chassis.enums import ButtonColor, RowActionDisplay
from django_chassis.options import TableActionOption, TableActionUrlKwargOption, TableColumnOption, TableOption

TableOption(
columns=[TableColumnOption(field='title', label='Title'), TableColumnOption(field='status', label='Status')],
fieldset_title='Items',
empty_message='No rows.',
selection_field='id',
actions=[
TableActionOption(
url_name='admin:catalog_book_change',
label='Open',
icon_class='fa-solid fa-arrow-right',
color=ButtonColor.PRIMARY,
display=RowActionDisplay.ICON,
object_field='id',
object_url_kwarg='object_id',
permission='view',
)
],
)

Columns

TableColumnOption.field is a dotted path on the row object. label is the column header.

Actions

TableActionOption builds a URL from url_name plus kwargs taken from the row.

ParameterTypeDefault
url_nameDjango URL namerequired
labellocalized stringrequired
icon_classFont Awesome classrequired
colorButtonColorPRIMARY
displayICON or BUTTONICON
object_fieldrow attribute for the object idid
object_url_kwargURL kwarg nameobject_id
permissioncodename or NoneNone
condition_methodmethod name or NoneNone
url_kwargsextra TableActionUrlKwargOption[]

TableActionUrlKwargOption(name=..., value=...) is a constant extra reverse() kwarg. The per-row object id still comes from object_field. An unnamespaced url_name is prefixed with the current AdminSite name.

Selection

  • selection_field — row attribute used as the checkbox value
  • selection_disabled_field — when truthy, the row cannot be selected
  • selection_checked_field — when truthy, the row starts checked

Empty state

empty_message is shown when the provider returns no rows.

TableService and PaginationService render and paginate these tables. You rarely call them directly.

See also