mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes: #14839 - Check for tunnel termination type in data and instance in addition to intially passed data. (#14995)
* Fixes: #14839 - Check for tunnel termination type in additional instances * Incorporate recommended changes
This commit is contained in:
@ -265,9 +265,15 @@ class TunnelTerminationForm(NetBoxModelForm):
|
||||
def __init__(self, *args, initial=None, **kwargs):
|
||||
super().__init__(*args, initial=initial, **kwargs)
|
||||
|
||||
if initial and initial.get('type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE:
|
||||
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 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'
|
||||
self.fields['termination'].queryset = VMInterface.objects.all()
|
||||
self.fields['termination'].widget.add_query_params({
|
||||
'virtual_machine_id': '$parent',
|
||||
|
Reference in New Issue
Block a user