From 83e21bd9980d41cf52e0f0e14df16e5759bf37e4 Mon Sep 17 00:00:00 2001 From: Jason Novinger Date: Wed, 12 Mar 2025 14:15:41 -0500 Subject: [PATCH] Remove accessor/order_by and modify DEVICE_LINK template Thanks to @alehaa for the suggestion. This also includes an additional `.select_related()` operation on `DeviceListView.queryset` to avoid extra queries. Thanks to @renatoalmeidaoliveira and @jeremystretch for pointing out the need for this. --- netbox/dcim/tables/devices.py | 2 -- netbox/dcim/tables/template_code.py | 2 +- netbox/dcim/views.py | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 55ba05889..5320820cd 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -143,10 +143,8 @@ class PlatformTable(NetBoxTable): class DeviceTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable): name = tables.TemplateColumn( verbose_name=_('Name'), - accessor=Accessor('label'), template_code=DEVICE_LINK, linkify=True, - order_by=('name',) ) status = columns.ChoiceFieldColumn( verbose_name=_('Status'), diff --git a/netbox/dcim/tables/template_code.py b/netbox/dcim/tables/template_code.py index 1c526649b..aa5978d93 100644 --- a/netbox/dcim/tables/template_code.py +++ b/netbox/dcim/tables/template_code.py @@ -35,7 +35,7 @@ WEIGHT = """ """ DEVICE_LINK = """ -{{ value|default:'Unnamed device' }} +{{ record.label|default:'Unnamed device' }} """ DEVICEBAY_STATUS = """ diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 60de8c355..172a1b5d9 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -2025,7 +2025,7 @@ class PlatformBulkDeleteView(generic.BulkDeleteView): @register_model_view(Device, 'list', path='', detail=False) class DeviceListView(generic.ObjectListView): - queryset = Device.objects.all() + queryset = Device.objects.select_related('virtual_chassis') filterset = filtersets.DeviceFilterSet filterset_form = forms.DeviceFilterForm table = tables.DeviceTable