mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-29 20:06:25 -06:00
Enforce saving only a single is_primary MACAddress per interface/vminterface
This commit is contained in:
parent
3f32c5b123
commit
3a7a4f83d6
@ -923,6 +923,14 @@ class MACAddressForm(NetBoxModelForm):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def clean_is_primary(self):
|
||||
# If setting this MACAddress to primary, unset all the rest on this interface
|
||||
if is_primary := self.cleaned_data['is_primary']:
|
||||
if interface := self.cleaned_data['interface']:
|
||||
interface.mac_addresses.all().update(is_primary=False)
|
||||
if vminterface := self.cleaned_data['vminterface']:
|
||||
vminterface.mac_addresses.all().update(is_primary=False)
|
||||
return is_primary
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
Loading…
Reference in New Issue
Block a user