From f2a0cc8d36b300095d4ba68015ad11800dcff788 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 12 Oct 2022 08:27:52 -0700 Subject: [PATCH 1/2] 9584 add device type (slug) to filter list --- netbox/dcim/filtersets.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/netbox/dcim/filtersets.py b/netbox/dcim/filtersets.py index 0a4439173fa..a999383c7db 100644 --- a/netbox/dcim/filtersets.py +++ b/netbox/dcim/filtersets.py @@ -800,6 +800,12 @@ class DeviceFilterSet(NetBoxModelFilterSet, TenancyFilterSet, ContactModelFilter to_field_name='slug', label='Manufacturer (slug)', ) + device_type = django_filters.ModelMultipleChoiceFilter( + field_name='device_type__slug', + queryset=DeviceType.objects.all(), + to_field_name='slug', + label='Device type (slug)', + ) device_type_id = django_filters.ModelMultipleChoiceFilter( queryset=DeviceType.objects.all(), label='Device type (ID)', From 414494ed644af5e57664bdfe9b3c163728b91614 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 19 Oct 2022 09:50:44 -0700 Subject: [PATCH 2/2] 9584 add test --- netbox/dcim/tests/test_filtersets.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/netbox/dcim/tests/test_filtersets.py b/netbox/dcim/tests/test_filtersets.py index feef4e90c7e..05bb647964f 100644 --- a/netbox/dcim/tests/test_filtersets.py +++ b/netbox/dcim/tests/test_filtersets.py @@ -1643,6 +1643,8 @@ def test_devicetype(self): device_types = DeviceType.objects.all()[:2] params = {'device_type_id': [device_types[0].pk, device_types[1].pk]} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) + params = {'device_type': [device_types[0].slug, device_types[1].slug]} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) def test_devicerole(self): device_roles = DeviceRole.objects.all()[:2]