From 7cbea49c2dd5ecc6dfdcea1cc55f52c1b92fe025 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 12 Apr 2017 15:51:14 -0400 Subject: [PATCH] Fixes #1072: Order LAG interfaces naturally on bulk interface edit form --- netbox/dcim/forms.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 32b8850f6..8967936ad 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -1422,9 +1422,16 @@ class InterfaceBulkEditForm(BootstrapMixin, BulkEditForm): super(InterfaceBulkEditForm, self).__init__(*args, **kwargs) # Limit LAG choices to interfaces which belong to the parent device. + device = None 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: self.fields['lag'].choices = []