mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Clean CircuitTerminationForm data to avoid model ValidationErrors
Associated with issue #11891
This commit is contained in:
parent
dffb6fa329
commit
d35acf0a01
@ -169,3 +169,17 @@ class CircuitTerminationForm(NetBoxModelForm):
|
|||||||
labels = {
|
labels = {
|
||||||
'termination_type': 'Termination Type',
|
'termination_type': 'Termination Type',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
termination_type = self.cleaned_data.get('termination_type')
|
||||||
|
|
||||||
|
# Clear out the unselected termination type fields to prevent a ValidationError in the model.
|
||||||
|
# Otherwise, users would have to manually clear out the site or provider network field, before
|
||||||
|
# changing the termination type. That behavior may not be obvious or convenient for most users.
|
||||||
|
if termination_type != CircuitTerminationTypeChoices.SITE:
|
||||||
|
self.cleaned_data['site'] = None
|
||||||
|
|
||||||
|
if termination_type != CircuitTerminationTypeChoices.PROVIDER_NETWORK:
|
||||||
|
self.cleaned_data['provider_network'] = None
|
||||||
|
Loading…
Reference in New Issue
Block a user