Browse Source

Fixes #1072: Order LAG interfaces naturally on bulk interface edit form

Jeremy Stretch 8 years ago
parent
commit
7cbea49c2d
1 changed files with 9 additions and 2 deletions
  1. 9 2
      netbox/dcim/forms.py

+ 9 - 2
netbox/dcim/forms.py

@@ -1422,9 +1422,16 @@ class InterfaceBulkEditForm(BootstrapMixin, BulkEditForm):
         super(InterfaceBulkEditForm, self).__init__(*args, **kwargs)
         super(InterfaceBulkEditForm, self).__init__(*args, **kwargs)
 
 
         # Limit LAG choices to interfaces which belong to the parent device.
         # Limit LAG choices to interfaces which belong to the parent device.
+        device = None
         if self.initial.get('device'):
         if self.initial.get('device'):
-            self.fields['lag'].queryset = Interface.objects.filter(
-                device=self.initial['device'], form_factor=IFACE_FF_LAG
+            try:
+                device = Device.objects.get(pk=self.initial.get('device'))
+            except Device.DoesNotExist:
+                pass
+        if device is not None:
+            interface_ordering = device.device_type.interface_ordering
+            self.fields['lag'].queryset = Interface.objects.order_naturally(method=interface_ordering).filter(
+                device=device, form_factor=IFACE_FF_LAG
             )
             )
         else:
         else:
             self.fields['lag'].choices = []
             self.fields['lag'].choices = []