1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #2742: Preserve cluster assignment when editing a device

This commit is contained in:
Jeremy Stretch
2019-01-04 11:46:53 -05:00
parent 848aa0b098
commit 99dc46a89e
2 changed files with 10 additions and 3 deletions

View File

@ -1213,11 +1213,13 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm):
# Initialize helper selectors
instance = kwargs.get('instance')
if 'initial' not in kwargs:
kwargs['initial'] = {}
# Using hasattr() instead of "is not None" to avoid RelatedObjectDoesNotExist on required field
if instance and hasattr(instance, 'device_type'):
initial = kwargs.get('initial', {}).copy()
initial['manufacturer'] = instance.device_type.manufacturer
kwargs['initial'] = initial
kwargs['initial']['manufacturer'] = instance.device_type.manufacturer
if instance and instance.cluster is not None:
kwargs['initial']['cluster_group'] = instance.cluster.group
super().__init__(*args, **kwargs)