mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Adapt component creation forms to infer parent device/VM from initial or bound data
This commit is contained in:
@ -797,9 +797,12 @@ class InterfaceCreateForm(ComponentForm):
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
virtual_machine = VirtualMachine.objects.get(
|
||||
pk=self.initial.get('virtual_machine') or self.data.get('virtual_machine')
|
||||
)
|
||||
|
||||
# Limit VLAN choices to those in: global vlans, global groups, the current site's group, the current site
|
||||
vlan_choices = []
|
||||
global_vlans = VLAN.objects.filter(site=None, group=None)
|
||||
@ -812,8 +815,7 @@ class InterfaceCreateForm(ComponentForm):
|
||||
(group.name, [(vlan.pk, vlan) for vlan in global_group_vlans])
|
||||
)
|
||||
|
||||
parent = VirtualMachine.objects.get(pk=self.initial.get('virtual_machine'))
|
||||
site = getattr(parent.cluster, 'site', None)
|
||||
site = getattr(virtual_machine.cluster, 'site', None)
|
||||
if site is not None:
|
||||
|
||||
# Add non-grouped site VLANs
|
||||
|
Reference in New Issue
Block a user