Explorar o código

Fixes #9096: Remove duplicate filter tag when filtering by "none"

jeremystretch %!s(int64=3) %!d(string=hai) anos
pai
achega
517d0158b6
Modificáronse 2 ficheiros con 6 adicións e 5 borrados
  1. 1 0
      docs/release-notes/version-3.2.md
  2. 5 5
      netbox/utilities/forms/utils.py

+ 1 - 0
docs/release-notes/version-3.2.md

@@ -15,6 +15,7 @@
 * [#9061](https://github.com/netbox-community/netbox/issues/9061) - Change inheritance order for DeviceComponentFilterSets
 * [#9065](https://github.com/netbox-community/netbox/issues/9065) - Min/max VID should not be required when filtering VLAN groups
 * [#9079](https://github.com/netbox-community/netbox/issues/9079) - Fail validation when an inventory item is assigned as its own parent
+* [#9096](https://github.com/netbox-community/netbox/issues/9096) - Remove duplicate filter tag when filtering by "none"
 * [#9100](https://github.com/netbox-community/netbox/issues/9100) - Include position field in module type YAML export
 
 ---

+ 5 - 5
netbox/utilities/forms/utils.py

@@ -144,11 +144,11 @@ def get_selected_values(form, field_name):
             label for value, label in choices if str(value) in filter_data or None in filter_data
         ]
 
-    if hasattr(field, 'null_option'):
-        # If the field has a `null_option` attribute set and it is selected,
-        # add it to the field's grouped choices.
-        if field.null_option is not None and None in filter_data:
-            values.append(field.null_option)
+    # If the field has a `null_option` attribute set and it is selected,
+    # add it to the field's grouped choices.
+    if getattr(field, 'null_option') and None in filter_data:
+        values.remove(None)
+        values.insert(0, field.null_option)
 
     return values