Files
Netbox-Utilities/netbox_utilities/inventory_assets.py
T
MrBlakeandClaude Opus 5.5 f86306e686 feat: show tenant column in netbox-inventory asset list
The asset table of netbox-inventory gets a tenant column (registered if the
plugin does not provide one) that is part of the default columns, placed
right after the status.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 12:50:42 +01:00

28 lines
1.0 KiB
Python

import django_tables2 as tables
from django.utils.translation import gettext_lazy as _
COLUMN_NAME = "tenant"
def add_to_default_columns(table, column=COLUMN_NAME, after=("status", "asset_tag", "hardware_type")):
"""Show the column by default (users without saved table preferences), next to the status."""
defaults = [name for name in table.Meta.default_columns if name != column]
for anchor in after:
if anchor in defaults:
defaults.insert(defaults.index(anchor) + 1, column)
break
else:
defaults.append(column)
table.Meta.default_columns = tuple(defaults)
def install_asset_tenant_column():
"""Show the tenant of every netbox-inventory asset in the asset list."""
from netbox_inventory.tables import AssetTable
if COLUMN_NAME not in AssetTable.base_columns:
from utilities.tables import register_table_column
register_table_column(tables.Column(linkify=True, verbose_name=_("Tenant")), COLUMN_NAME, AssetTable)
add_to_default_columns(AssetTable)