|
|
@@ -1,5 +1,6 @@
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
from rest_framework.fields import Field
|
|
|
+from rest_framework.serializers import ValidationError
|
|
|
|
|
|
from extras.choices import CustomFieldTypeChoices
|
|
|
from extras.models import CustomField
|
|
|
@@ -62,6 +63,12 @@ class CustomFieldsDataField(Field):
|
|
|
return data
|
|
|
|
|
|
def to_internal_value(self, data):
|
|
|
+ if type(data) is not dict:
|
|
|
+ raise ValidationError(
|
|
|
+ "Invalid data format. Custom field data must be passed as a dictionary mapping field names to their "
|
|
|
+ "values."
|
|
|
+ )
|
|
|
+
|
|
|
# If updating an existing instance, start with existing custom_field_data
|
|
|
if self.parent.instance:
|
|
|
data = {**self.parent.instance.custom_field_data, **data}
|