Skip to content
Snippets Groups Projects

Refactor update creation api

Merged Samuel GAIST requested to merge refactor_update_creation_api into master
1 file
+ 0
14
Compare changes
  • Side-by-side
  • Inline
+ 10
10
@@ -25,22 +25,22 @@
# #
###############################################################################
from rest_framework import serializers
from django.utils import six
import simplejson as json
import simplejson
from rest_framework import serializers
from rest_framework.fields import JSONField as drf_JSONField
class StringListField(serializers.ListField):
child = serializers.CharField()
class JSONSerializerField(serializers.Field):
""" Serializer for JSONField -- required to make field writable"""
class JSONField(drf_JSONField):
def to_internal_value(self, data):
if isinstance(data, six.string_types):
return simplejson.loads(data)
return data
if isinstance(data, str):
try:
data = json.loads(data)
except json.errors.JSONDecodeError:
self.fail("invalid")
def to_representation(self, value):
return value
return super().to_internal_value(data)
Loading