Clean up validation error messages

This commit is contained in:
jeremystretch 2023-04-12 10:12:32 -04:00
parent a5d078ce55
commit f989da77bb
2 changed files with 10 additions and 6 deletions

View File

@ -122,7 +122,9 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
def __init__(self, *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):
objectchange = super().to_objectchange(action)
@ -135,9 +137,9 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
def clean(self):
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({
"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

View File

@ -80,7 +80,9 @@ class ComponentModel(NetBoxModel):
def __init__(self, *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):
if self.label:
@ -95,9 +97,9 @@ class ComponentModel(NetBoxModel):
def clean(self):
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({
"device": "Device field is read-only and not updatable."
"device": "Components cannot be moved to a different device."
})
@property