Arthur il y a 6 jours
Parent
commit
5278ccbae2
2 fichiers modifiés avec 14 ajouts et 2 suppressions
  1. 11 0
      netbox/extras/tests/test_customfields.py
  2. 3 2
      netbox/netbox/tables/columns.py

+ 11 - 0
netbox/extras/tests/test_customfields.py

@@ -102,6 +102,17 @@ class CustomFieldTestCase(TestCase):
         queryset, _ = column.order(Site.objects.all(), is_descending=False)
         self.assertEqual(list(queryset), [site_a, site_b, site_c])
 
+        # Null placement is independent of sort direction: nulls_first=True keeps the null value
+        # first even when sorting descending
+        cf.nulls_first = True
+        queryset, _ = column.order(Site.objects.all(), is_descending=True)
+        self.assertEqual(list(queryset), [site_c, site_b, site_a])
+
+        # nulls_first=False keeps the null value last even when sorting descending
+        cf.nulls_first = False
+        queryset, _ = column.order(Site.objects.all(), is_descending=True)
+        self.assertEqual(list(queryset), [site_b, site_a, site_c])
+
     def test_longtext_field(self):
         value = 'A' * 256
 

+ 3 - 2
netbox/netbox/tables/columns.py

@@ -515,10 +515,11 @@ class CustomFieldColumn(tables.Column):
         kwargs['accessor'] = Accessor(f'custom_field_data__{customfield.name}')
         if 'verbose_name' not in kwargs:
             kwargs['verbose_name'] = customfield.label or customfield.name
-        # We can't logically sort on FK values
+        # We can't logically sort on FK values, nor on multi-value (array) fields
         if customfield.type in (
             CustomFieldTypeChoices.TYPE_OBJECT,
-            CustomFieldTypeChoices.TYPE_MULTIOBJECT
+            CustomFieldTypeChoices.TYPE_MULTIOBJECT,
+            CustomFieldTypeChoices.TYPE_MULTISELECT,
         ):
             kwargs['orderable'] = False