From 78332d44c716250de04f1c3e44739053bd00c562 Mon Sep 17 00:00:00 2001 From: Jason Novinger Date: Thu, 13 Mar 2025 09:22:49 -0400 Subject: [PATCH] Fixes #18845: restores sort behavior for DeviceTable.name column (#18861) * Fixes #18845: restores sort behavior for DeviceTable.name column * 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 | 3 +-- netbox/dcim/tables/template_code.py | 2 +- netbox/dcim/views.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 25875d7bb..5320820cd 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -143,9 +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 + linkify=True, ) 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 f63a0ad79..1c54f93d1 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -2034,7 +2034,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