11432 fix fk accessor

This commit is contained in:
Arthur 2023-04-10 14:02:16 -07:00
parent a5f751ce09
commit a5d078ce55
3 changed files with 12 additions and 2 deletions

View File

@ -897,6 +897,7 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
]
def validate(self, data):
# Validate many-to-many VLAN assignments
device = self.instance.device if self.instance else data.get('device')
for vlan in data.get('tagged_vlans', []):

View File

@ -120,6 +120,10 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
),
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__original_device_type = self.device_type_id
def to_objectchange(self, action):
objectchange = super().to_objectchange(action)
if self.device_type is not None:
@ -131,6 +135,11 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
def clean(self):
super().clean()
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."
})
# A component template must belong to a DeviceType *or* to a ModuleType
if self.device_type and self.module_type:
raise ValidationError(

View File

@ -80,7 +80,7 @@ class ComponentModel(NetBoxModel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__original_device = self.device
self.__original_device = self.device_id
def __str__(self):
if self.label:
@ -95,7 +95,7 @@ class ComponentModel(NetBoxModel):
def clean(self):
super().clean()
if self.pk is None and self.__original_device != self.device:
if self.pk is not None and self.__original_device != self.device_id:
raise ValidationError({
"device": "Device field is read-only and not updatable."
})