Modify clean() on model and form to properly catch error

This commit is contained in:
Daniel Sheppard 2023-12-18 09:44:55 -06:00
parent 6aa4670c39
commit b9b24d9399
2 changed files with 4 additions and 6 deletions

View File

@ -375,7 +375,7 @@ class IPAddressForm(TenancyForm, NetBoxModelForm):
if prev_parent.primary_ip4 == self.instance or prev_parent.primary_ip6 == self.instance: if prev_parent.primary_ip4 == self.instance or prev_parent.primary_ip6 == self.instance:
self.add_error( self.add_error(
selected_objects[0], selected_objects[0],
_("Cannot reassign IP address while it is designated as the primary ip for the parent object") _("Cannot reassign IP address while it is designated as the primary IP for the parent object")
) )
# Do not allow assigning a network ID or broadcast address to an interface. # Do not allow assigning a network ID or broadcast address to an interface.

View File

@ -864,11 +864,9 @@ class IPAddress(PrimaryModel):
is_primary = True is_primary = True
if is_primary and (parent != original_parent): if is_primary and (parent != original_parent):
raise ValidationError({ raise ValidationError(
'assigned_object': _( _("Cannot reassign IP address while it is designated as the primary IP for the parent object")
"Cannot reassign IP address while it is designated as the primary IP for the parent object" )
)
})
# Validate IP status selection # Validate IP status selection
if self.status == IPAddressStatusChoices.STATUS_SLAAC and self.family != 6: if self.status == IPAddressStatusChoices.STATUS_SLAAC and self.family != 6: