mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 17:26:10 -06:00
11432 fix fk accessor
This commit is contained in:
parent
a5f751ce09
commit
a5d078ce55
@ -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', []):
|
||||
|
@ -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(
|
||||
|
@ -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."
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user