From 34f7872f99cb20e073e5db5a9764add664b21cdc Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Fri, 2 Feb 2024 16:22:10 -0600 Subject: [PATCH] Incorporate recommended changes --- netbox/vpn/forms/model_forms.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/netbox/vpn/forms/model_forms.py b/netbox/vpn/forms/model_forms.py index 4decd29cf..f936de88c 100644 --- a/netbox/vpn/forms/model_forms.py +++ b/netbox/vpn/forms/model_forms.py @@ -265,14 +265,12 @@ class TunnelTerminationForm(NetBoxModelForm): def __init__(self, *args, initial=None, **kwargs): super().__init__(*args, initial=initial, **kwargs) + if (get_field_value(self, 'type') is None and + self.instance.pk and isinstance(self.instance.termination.parent_object, VirtualMachine)): + self.fields['type'].initial = TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE + # If initial or self.data is set and the type is a VIRTUALMACHINE type, swap the field querysets. - if ( - initial and initial.get('type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE - ) or ( - self.data and self.data.get('type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE - ) or ( - self.instance.pk and isinstance(self.instance.termination.parent_object, VirtualMachine) - ): + if get_field_value(self, 'type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE: self.fields['parent'].label = _('Virtual Machine') self.fields['parent'].queryset = VirtualMachine.objects.all() self.fields['parent'].widget.attrs['selector'] = 'virtualization.virtualmachine'