Update validation to model clean method instead of serializer

This commit is contained in:
Daniel Sheppard 2024-08-25 15:37:59 -05:00
parent d4c8e88fd7
commit bab5a5b273
2 changed files with 6 additions and 7 deletions

View File

@ -247,13 +247,6 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
f"or it must be global."
})
# Validate that tagged-all payload does not include tagged_vlans
mode = data.get('mode') or getattr(self.instance, 'mode', None)
if mode == InterfaceModeChoices.MODE_TAGGED_ALL and data.get('tagged_vlans'):
raise serializers.ValidationError({
'tagged_vlans': "Tagged-All interface mode must not include any tagged vlans"
})
return super().validate(data)

View File

@ -904,6 +904,12 @@ class Interface(ModularComponentModel, BaseInterface, CabledObjectModel, PathEnd
).format(untagged_vlan=self.untagged_vlan)
})
# Validate that tagged-all payload does not include tagged_vlans
if self.mode != InterfaceModeChoices.MODE_TAGGED and self.tagged_vlans:
raise ValidationError({
'tagged_vlans': "Interface mode does not support including tagged vlans"
})
def save(self, *args, **kwargs):
# Set absolute channel attributes from selected options