⚡️(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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user