✨(documents) add content field as an S3 object
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.
This commit is contained in:
committed by
Anthony LC
parent
4956beb040
commit
8e262da8f5
24
src/backend/core/api/fields.py
Normal file
24
src/backend/core/api/fields.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""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)
|
||||
@@ -7,6 +7,8 @@ from timezone_field.rest_framework import TimeZoneSerializerField
|
||||
|
||||
from core import models
|
||||
|
||||
from .fields import JSONField
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
"""Serialize users."""
|
||||
@@ -134,6 +136,8 @@ class BaseResourceSerializer(serializers.ModelSerializer):
|
||||
class DocumentSerializer(BaseResourceSerializer):
|
||||
"""Serialize documents."""
|
||||
|
||||
content = JSONField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = models.Document
|
||||
fields = ["id", "content", "title", "accesses", "abilities", "is_public"]
|
||||
|
||||
Reference in New Issue
Block a user