nautobot.apps.tables
¶
Utilities for apps to implement data tables.
nautobot.apps.tables.BaseTable
¶
Bases: Table
Default table for object lists
:param user: Personalize table display for the given user (optional). Has no effect if AnonymousUser is passed.
__init__(*args, table_changes_pending=False, saved_view=None, user=None, hide_hierarchy_ui=False, order_by=None, data_transform_callback=None, **kwargs)
¶
Instantiate a BaseTable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
list
|
Passed through to django_tables2.Table |
()
|
table_changes_pending |
bool
|
TODO |
False
|
saved_view |
SavedView
|
TODO |
None
|
user |
User
|
TODO |
None
|
hide_hierarchy_ui |
bool
|
Whether to display or hide hierarchy indentation of nested objects. |
False
|
order_by |
list
|
Field(s) to sort by |
None
|
data_transform_callback |
function
|
A function that takes the given |
None
|
**kwargs |
dict
|
Passed through to django_tables2.Table |
{}
|
Warning:
Do not modify/set the base_columns
attribute after BaseTable class is instantiated.
Do not modify/set the base_columns
attribute after calling super().init() of BaseTable class.
nautobot.apps.tables.BooleanColumn
¶
Bases: Column
Custom implementation of BooleanColumn to render a nicely-formatted checkmark or X icon instead of a Unicode character.
nautobot.apps.tables.ButtonsColumn
¶
Bases: TemplateColumn
Render edit, delete, and changelog buttons for an object.
:param model: Model class to use for calculating URL view names :param prepend_template: Additional template content to render in the column (optional) :param return_url_extra: String to append to the return URL (e.g. for specifying a tab) (optional)
nautobot.apps.tables.ChoiceFieldColumn
¶
Bases: Column
Render a ChoiceField value inside a indicating a particular CSS class. This is useful for displaying colored choices. The CSS class is derived by calling .get_FOO_class() on the row record.
nautobot.apps.tables.ColorColumn
¶
Bases: Column
Display a color (#RRGGBB).
nautobot.apps.tables.ColoredLabelColumn
¶
Bases: TemplateColumn
Render a colored label (e.g. for DeviceRoles).
nautobot.apps.tables.ComputedFieldColumn
¶
Bases: Column
Display computed fields in the appropriate format.
nautobot.apps.tables.ContentTypesColumn
¶
Bases: ManyToManyColumn
Display a list of content_types
m2m assigned to an object.
Default sorting of content-types is by pk. This sorting comes at a per-row
performance hit to querysets for table views. If this becomes an issue,
set sort_items=False
.
:param sort_items: Whether to sort by (app_label, name)
. (default: True)
:param truncate_words:
Number of words at which to truncate, or None
to disable. (default: None)
nautobot.apps.tables.CustomFieldColumn
¶
Bases: Column
Display custom fields in the appropriate format.
nautobot.apps.tables.LinkedCountColumn
¶
Bases: Column
Render a count of related objects linked to a filtered URL, or if a single related object is present, the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
viewname |
str
|
The list view name to use for URL resolution, for example |
required |
url_params |
dict
|
Query parameters to apply to filter the list URL (e.g. |
None
|
view_kwargs |
dict
|
Additional kwargs to pass to |
None
|
lookup |
str
|
The field name on the base record that can be used to query the related objects.
If not specified, |
None
|
reverse_lookup |
str
|
The reverse lookup parameter to use to derive the count.
If not specified, the first key in |
None
|
distinct |
bool
|
Parameter passed through to |
False
|
**kwargs |
dict
|
As the parent Column class. |
{}
|
Examples:
class VLANTable(..., BaseTable):
...
location_count = LinkedCountColumn(
# Link for N related locations will be reverse("dcim:location_list") + "?vlans=<record.pk>"
viewname="dcim:location_list",
url_params={"vlans": "pk"},
verbose_name="Locations",
)
class CloudNetworkTable(BaseTable):
...
circuit_count = LinkedCountColumn(
# Link for N related circuits will be reverse("circuits:circuit_list") + "?cloud_network=<record.name>"
viewname="circuits:circuit_list",
url_params={"cloud_network": "name"},
# We'd like to do the below but this module isn't currently smart enough to build the right Prefetch()
# for a nested lookup:
# lookup="circuit_terminations__circuit",
# For the count,
# .annotate(circuit_count=count_related(Circuit, "circuit_terminations__cloud_network", distinct=True))
reverse_lookup="circuit_terminations__cloud_network",
distinct=True,
verbose_name="Circuits",
)
nautobot.apps.tables.RelationshipColumn
¶
Bases: Column
Display relationship association instances in the appropriate format.
nautobot.apps.tables.TableExtension
¶
Template class for extending Tables.
An app can override the default columns for a table by either: - Extending the original default columns to include custom columns. - add_to_default_columns = ("my_app_name_new_column",) - Removing native columns from the default columns. - remove_from_default_columns = ("tenant",)
alter_queryset(queryset)
classmethod
¶
Alter the View class QuerySet.
This is a good place to add prefetch_related
to the view queryset.
example:
return queryset.prefetch_related("my_model_set")
nautobot.apps.tables.TagColumn
¶
Bases: TemplateColumn
Display a list of tags assigned to the object.
nautobot.apps.tables.ToggleColumn
¶
Bases: CheckBoxColumn
Extend CheckBoxColumn to add a "toggle all" checkbox in the column header.