mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 17:26:10 -06:00
Clean up validation error messages
This commit is contained in:
parent
a5d078ce55
commit
f989da77bb
@ -122,7 +122,9 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.__original_device_type = self.device_type_id
|
|
||||||
|
# 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)
|
||||||
@ -135,9 +137,9 @@ 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:
|
if self.pk is not None and self._original_device_type != self.device_type_id:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
"device": "device_type field is read-only and not updatable."
|
"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
|
||||||
|
@ -80,7 +80,9 @@ class ComponentModel(NetBoxModel):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.__original_device = self.device_id
|
|
||||||
|
# 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:
|
||||||
@ -95,9 +97,9 @@ class ComponentModel(NetBoxModel):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
if self.pk is not None and self.__original_device != self.device_id:
|
if self.pk is not None and self._original_device != self.device_id:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
"device": "Device field is read-only and not updatable."
|
"device": "Components cannot be moved to a different device."
|
||||||
})
|
})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
Reference in New Issue
Block a user