1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #11431 - Disallow changing customfield type after creation (#11449)

* Disallow changing customfield type after creation

* Fix test_api.CustomFieldTest

---------

Co-authored-by: kkthxbye-code <>
This commit is contained in:
kkthxbye
2023-04-10 16:13:08 +02:00
committed by GitHub
parent 768d6f624e
commit 278f2b173a
3 changed files with 18 additions and 0 deletions

View File

@@ -97,6 +97,12 @@ class CustomFieldSerializer(ValidatedModelSerializer):
'validation_minimum', 'validation_maximum', 'validation_regex', 'choices', 'created', 'last_updated',
]
def validate_type(self, value):
if self.instance and self.instance.type != value:
raise serializers.ValidationError('Changing the type of custom fields is not supported.')
return value
def get_data_type(self, obj):
types = CustomFieldTypeChoices
if obj.type == types.TYPE_INTEGER: