Browse Source

Fixes #2724: Limit rear port choices to current device when editing a front port

Jeremy Stretch 7 years ago
parent
commit
ebe5193348
2 changed files with 10 additions and 0 deletions
  1. 1 0
      CHANGELOG.md
  2. 9 0
      netbox/dcim/forms.py

+ 1 - 0
CHANGELOG.md

@@ -16,6 +16,7 @@ v2.5.2 (FUTURE)
 * [#2717](https://github.com/digitalocean/netbox/issues/2717) - Fix bulk deletion of tags
 * [#2721](https://github.com/digitalocean/netbox/issues/2721) - Detect loops when tracing front/rear ports
 * [#2723](https://github.com/digitalocean/netbox/issues/2723) - Correct permission evaluation when bulk deleting tags
+* [#2724](https://github.com/digitalocean/netbox/issues/2724) - Limit rear port choices to current device when editing a front port
 
 ---
 

+ 9 - 0
netbox/dcim/forms.py

@@ -2098,6 +2098,15 @@ class FrontPortForm(BootstrapMixin, forms.ModelForm):
             'device': forms.HiddenInput(),
         }
 
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        # Limit RearPort choices to the local device
+        if hasattr(self.instance, 'device'):
+            self.fields['rear_port'].queryset = self.fields['rear_port'].queryset.filter(
+                device=self.instance.device
+            )
+
 
 # TODO: Merge with FrontPortTemplateCreateForm to remove duplicate logic
 class FrontPortCreateForm(ComponentForm):