Perform is_primary validation on MACAddress model and just check if one already exists for the interface

This commit is contained in:
Brian Tiemann 2024-11-14 10:33:29 -05:00
parent 3a7a4f83d6
commit 5029dd4eaf

View File

@ -1516,3 +1516,12 @@ class MACAddress(PrimaryModel):
def __str__(self):
return f'{str(self.mac_address)} {self.assigned_object}'
def clean(self):
super().clean()
if self.is_primary and self.assigned_object:
if self.assigned_object.mac_addresses.filter(is_primary=True).exists():
raise ValidationError({
'is_primary': _("There is already a primary MAC address for this interface.")
})