mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 13:38:16 -06:00
Incorporate recommended changes
This commit is contained in:
parent
1c2107e793
commit
34f7872f99
@ -265,14 +265,12 @@ class TunnelTerminationForm(NetBoxModelForm):
|
|||||||
def __init__(self, *args, initial=None, **kwargs):
|
def __init__(self, *args, initial=None, **kwargs):
|
||||||
super().__init__(*args, initial=initial, **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 or self.data is set and the type is a VIRTUALMACHINE type, swap the field querysets.
|
||||||
if (
|
if get_field_value(self, 'type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE:
|
||||||
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)
|
|
||||||
):
|
|
||||||
self.fields['parent'].label = _('Virtual Machine')
|
self.fields['parent'].label = _('Virtual Machine')
|
||||||
self.fields['parent'].queryset = VirtualMachine.objects.all()
|
self.fields['parent'].queryset = VirtualMachine.objects.all()
|
||||||
self.fields['parent'].widget.attrs['selector'] = 'virtualization.virtualmachine'
|
self.fields['parent'].widget.attrs['selector'] = 'virtualization.virtualmachine'
|
||||||
|
Loading…
Reference in New Issue
Block a user