6๐
โ
You can override the to_internal_value
and to_representation
in a new serializer field to handle the return data for JSON field.
class JSONSerializerField(serializers.Field):
"""Serializer for JSONField -- required to make field writable"""
def to_internal_value(self, data):
return data
def to_representation(self, value):
return value
And in turn, you would use this Field in a serializer:
class SomeSerializer(serializers.ModelSerializer):
json_field = JSONSerializerField()
class Meta:
model = SomeModelClass
fields = ('json_field', )
This should solve your problem ๐
๐คuser8904707
0๐
When I originally created the columns I did it with a different json field package. The base DB columns was actually text instead of json or jsonb. Creating new columns (django json fields), migrating the data, and then shifting the data back got my database back in a consistent order.
๐คJohn Rake
- [Django]-Show request.DATA in Django 500 error caused by Rest Framework
- [Django]-Is it a bad practice to use sleep() in a web server in production?
- [Django]-What may cause a Page Not Found error in flatpages?
Source:stackexchange.com