Skip to content

Commit

Permalink
Fixes #13293: Limit interface selector for IP address to current devi…
Browse files Browse the repository at this point in the history
…ce/VM
  • Loading branch information
jeremystretch committed May 14, 2024
1 parent 69545fd commit 0b7804c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions netbox/ipam/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ def __init__(self, *args, **kwargs):
):
self.initial['primary_for_parent'] = True

if type(instance.assigned_object) is Interface:
self.fields['interface'].widget.add_query_params({
'device_id': instance.assigned_object.device.pk,
})
elif type(instance.assigned_object) is VMInterface:
self.fields['vminterface'].widget.add_query_params({
'virtual_machine_id': instance.assigned_object.virtual_machine.pk,
})

# Disable object assignment fields if the IP address is designated as primary
if self.initial.get('primary_for_parent'):
self.fields['interface'].disabled = True
Expand Down

0 comments on commit 0b7804c

Please sign in to comment.