Просмотр исходного кода

Fixes #2852: Allow filtering devices by null rack position

Jeremy Stretch 7 лет назад
Родитель
Сommit
993e94c00c
3 измененных файлов с 12 добавлено и 1 удалено
  1. 1 0
      CHANGELOG.md
  2. 6 0
      netbox/dcim/constants.py
  3. 5 1
      netbox/dcim/filters.py

+ 1 - 0
CHANGELOG.md

@@ -11,6 +11,7 @@ v2.5.7 (FUTURE)
 
 ## Bug Fixes
 
+* [#2852](https://github.com/digitalocean/netbox/issues/2852) - Allow filtering devices by null rack position
 * [#2884](https://github.com/digitalocean/netbox/issues/2884) - Don't display connect button for wireless interfaces
 * [#2888](https://github.com/digitalocean/netbox/issues/2888) - Correct foreground color of device roles in rack elevations
 * [#2893](https://github.com/digitalocean/netbox/issues/2893) - Remove duplicate display of VRF RD on IP address view

+ 6 - 0
netbox/dcim/constants.py

@@ -43,6 +43,12 @@ RACK_STATUS_CHOICES = [
     [RACK_STATUS_DEPRECATED, 'Deprecated'],
 ]
 
+# Device rack position
+DEVICE_POSITION_CHOICES = [
+    # Rack.u_height is limited to 100
+    (i, 'Unit {}'.format(i)) for i in range(1, 101)
+]
+
 # Parent/child device roles
 SUBDEVICE_ROLE_PARENT = True
 SUBDEVICE_ROLE_CHILD = False

+ 5 - 1
netbox/dcim/filters.py

@@ -543,6 +543,10 @@ class DeviceFilter(CustomFieldFilterSet):
         queryset=Rack.objects.all(),
         label='Rack (ID)',
     )
+    position = django_filters.ChoiceFilter(
+        choices=DEVICE_POSITION_CHOICES,
+        null_label='Non-racked'
+    )
     cluster_id = django_filters.ModelMultipleChoiceFilter(
         queryset=Cluster.objects.all(),
         label='VM cluster (ID)',
@@ -602,7 +606,7 @@ class DeviceFilter(CustomFieldFilterSet):
 
     class Meta:
         model = Device
-        fields = ['serial', 'position', 'face']
+        fields = ['serial', 'face']
 
     def search(self, queryset, name, value):
         if not value.strip():