mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
11432 device field (#11567)
* 11432 make device field on interface read-only on api edit call * 11432 make device field on interface read-only on api edit call * 11432 extend serializer change to mixin * 11432 add readonlydevicemixin to template serializers * 11432 change subclass ordering * 11432 fix device_type for template serializers * 11432 DRY * 11432 DRY * 11432 make internal var * 11432 change to model-level validation * 11432 fix fk accessor * Clean up validation error messages --------- Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
This commit is contained in:
parent
9e305c6181
commit
8de252e34e
@ -120,6 +120,12 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Cache the original DeviceType ID for reference under clean()
|
||||||
|
self._original_device_type = self.device_type_id
|
||||||
|
|
||||||
def to_objectchange(self, action):
|
def to_objectchange(self, action):
|
||||||
objectchange = super().to_objectchange(action)
|
objectchange = super().to_objectchange(action)
|
||||||
if self.device_type is not None:
|
if self.device_type is not None:
|
||||||
@ -131,6 +137,11 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
|
if self.pk is not None and self._original_device_type != self.device_type_id:
|
||||||
|
raise ValidationError({
|
||||||
|
"device_type": "Component templates cannot be moved to a different device type."
|
||||||
|
})
|
||||||
|
|
||||||
# A component template must belong to a DeviceType *or* to a ModuleType
|
# A component template must belong to a DeviceType *or* to a ModuleType
|
||||||
if self.device_type and self.module_type:
|
if self.device_type and self.module_type:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
|
@ -78,6 +78,12 @@ class ComponentModel(NetBoxModel):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Cache the original Device ID for reference under clean()
|
||||||
|
self._original_device = self.device_id
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.label:
|
if self.label:
|
||||||
return f"{self.name} ({self.label})"
|
return f"{self.name} ({self.label})"
|
||||||
@ -88,6 +94,14 @@ class ComponentModel(NetBoxModel):
|
|||||||
objectchange.related_object = self.device
|
objectchange.related_object = self.device
|
||||||
return objectchange
|
return objectchange
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
if self.pk is not None and self._original_device != self.device_id:
|
||||||
|
raise ValidationError({
|
||||||
|
"device": "Components cannot be moved to a different device."
|
||||||
|
})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent_object(self):
|
def parent_object(self):
|
||||||
return self.device
|
return self.device
|
||||||
|
Loading…
Reference in New Issue
Block a user