️(backend) remove content from Document serializer when asked

The frontend can fetch the retrieve endpoint just for having the title.
Everytime, the content is added and to get the content, a request is
made to the s3 bucket. A query string `without_content` can be used, if
the value is `true` then the content is not added (and not also not
fetch).
This commit is contained in:
Manuel Raynaud
2026-02-23 12:13:33 +01:00
parent 0d335105a1
commit ffae927c93
3 changed files with 56 additions and 2 deletions

View File

@@ -225,8 +225,16 @@ class DocumentSerializer(ListDocumentSerializer):
fields = super().get_fields()
request = self.context.get("request")
if request and request.method == "POST":
fields["id"].read_only = False
if request:
if request.method == "POST":
fields["id"].read_only = False
if (
serializers.BooleanField().to_internal_value(
request.query_params.get("without_content", False)
)
is True
):
del fields["content"]
return fields