mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #685: When assigning an IP to a device, automaitcally select the interface if only one exists
This commit is contained in:
@ -1252,10 +1252,15 @@ class IPAddressForm(BootstrapMixin, CustomFieldForm):
|
|||||||
|
|
||||||
self.fields['vrf'].empty_label = 'Global'
|
self.fields['vrf'].empty_label = 'Global'
|
||||||
|
|
||||||
self.fields['interface'].queryset = device.interfaces.all()
|
interfaces = device.interfaces.all()
|
||||||
|
self.fields['interface'].queryset = interfaces
|
||||||
self.fields['interface'].required = True
|
self.fields['interface'].required = True
|
||||||
|
|
||||||
# If this device does not have any IP addresses assigned, default to setting the first IP as its primary
|
# If this device has only one interface, select it by default.
|
||||||
|
if len(interfaces) == 1:
|
||||||
|
self.fields['interface'].initial = interfaces[0]
|
||||||
|
|
||||||
|
# If this device does not have any IP addresses assigned, default to setting the first IP as its primary.
|
||||||
if not IPAddress.objects.filter(interface__device=device).count():
|
if not IPAddress.objects.filter(interface__device=device).count():
|
||||||
self.fields['set_as_primary'].initial = True
|
self.fields['set_as_primary'].initial = True
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user