mySerializerWithJSON.py 460 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from backend_app.fields import JSONField
Florent Chehab's avatar
Florent Chehab committed
2 3 4
from rest_framework import serializers

field_mapping = serializers.ModelSerializer.serializer_field_mapping
Florent Chehab's avatar
Florent Chehab committed
5
# Small hack to register our custom JSONField class as a regular JSONfield
Florent Chehab's avatar
Florent Chehab committed
6 7 8 9 10
field_mapping[JSONField] = serializers.JSONField


class MySerializerWithJSON(serializers.ModelSerializer):
    """
Florent Chehab's avatar
Florent Chehab committed
11
    Simple class to add serializing support for custom JSONField
Florent Chehab's avatar
Florent Chehab committed
12
    """
13

Florent Chehab's avatar
Florent Chehab committed
14
    serializer_field_mapping = field_mapping