mirror of
https://github.com/suitenumerique/docs
synced 2026-04-21 13:37:20 +00:00
The content field is a writable property on the model which is persisted in object storage. We take advantage of the versioning, robustness and scalability of S3.
24 lines
597 B
Python
24 lines
597 B
Python
"""A JSONField for DRF to handle serialization/deserialization."""
|
|
import json
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
class JSONField(serializers.Field):
|
|
"""
|
|
A custom field for handling JSON data.
|
|
"""
|
|
|
|
def to_representation(self, value):
|
|
"""
|
|
Convert the JSON string to a Python dictionary for serialization.
|
|
"""
|
|
return value
|
|
|
|
def to_internal_value(self, data):
|
|
"""
|
|
Convert the Python dictionary to a JSON string for deserialization.
|
|
"""
|
|
if data is None:
|
|
return None
|
|
return json.dumps(data)
|