Fixes #8102 - Add validation around assigned objects

This commit is contained in:
Daniel Sheppard 2021-12-20 11:07:44 -06:00
parent 14fc37a8b8
commit 82932ae7a5
2 changed files with 15 additions and 0 deletions

View File

@ -22,6 +22,7 @@
* [#8088](https://github.com/netbox-community/netbox/issues/8088) - Improve legibility of text in labels with light-colored backgrounds
* [#8092](https://github.com/netbox-community/netbox/issues/8092) - Rack elevations should not include device asset tags
* [#8096](https://github.com/netbox-community/netbox/issues/8096) - Fix DataError during change logging of objects with very long string representations
* [#8102](https://github.com/netbox-community/netbox/issues/8102) - Cause validation error when editing IPAddress when more than one object is selected for assignment
---

View File

@ -461,6 +461,20 @@ class IPAddressForm(TenancyForm, CustomFieldModelForm):
def clean(self):
super().clean()
if self.cleaned_data['interface'] and self.cleaned_data['vminterface'] and self.cleaned_data['fhrpgroup']:
self.add_error('interface', "Can only assign an interface, VM interface or FHRP group")
self.add_error('vminterface', "Can only assign an interface, VM interface or FHRP group")
self.add_error('fhrpgroup', "Can only assign an interface, VM interface or FHRP group")
elif self.cleaned_data['interface'] and self.cleaned_data['vminterface']:
self.add_error('interface', "Can only assign an interface or VM interface")
self.add_error('vminterface', "Can only assign an interface or VM interface")
elif self.cleaned_data['interface'] and self.cleaned_data['fhrpgroup']:
self.add_error('interface', "Can only assign an interface or FHRP group")
self.add_error('fhrpgroup', "Can only assign an interface or FHRP group")
elif self.cleaned_data['vminterface'] and self.cleaned_data['fhrpgroup']:
self.add_error('vminterface', "Can only assign an VM interface or FHRP group")
self.add_error('fhrpgroup', "Can only assign an VM interface or FHRP group")
# Handle object assignment
if self.cleaned_data['interface']:
self.instance.assigned_object = self.cleaned_data['interface']