Disallow changing customfield type after creation

This commit is contained in:
kkthxbye-code 2023-01-10 09:36:07 +01:00
parent 30379c3f52
commit 28cad7c2f9
2 changed files with 13 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:

View File

@ -63,6 +63,13 @@ class CustomFieldForm(BootstrapMixin, forms.ModelForm):
'ui_visibility': StaticSelect(),
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Disable changing the type of a CustomField as it almost universally causes errors if custom field data is already present.
if self.instance.pk:
self.fields['type'].disabled = True
class CustomLinkForm(BootstrapMixin, forms.ModelForm):
content_types = ContentTypeMultipleChoiceField(