瀏覽代碼

Fixed RelatedObjectDoesNotExist error when trying to create a new device

Jeremy Stretch 8 年之前
父節點
當前提交
67282882fa
共有 1 個文件被更改,包括 2 次插入1 次删除
  1. 2 1
      netbox/dcim/forms.py

+ 2 - 1
netbox/dcim/forms.py

@@ -596,7 +596,8 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm):
 
 
         # Initialize helper selectors
         # Initialize helper selectors
         instance = kwargs.get('instance')
         instance = kwargs.get('instance')
-        if instance and instance.device_type is not None:
+        # Using hasattr() instead of "is not None" to avoid RelatedObjectDoesNotExist on required field
+        if instance and hasattr(instance, 'device_type'):
             initial = kwargs.get('initial', {})
             initial = kwargs.get('initial', {})
             initial['manufacturer'] = instance.device_type.manufacturer
             initial['manufacturer'] = instance.device_type.manufacturer
             kwargs['initial'] = initial
             kwargs['initial'] = initial