Skip to content
Snippets Groups Projects
Commit 648c10cc authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[code][serializers] Implement code field handling PUT

This includes both save and to_representation.
parent c3645414
No related branches found
No related tags found
1 merge request!327Refactor update creation api
......@@ -66,6 +66,23 @@ class CodeModSerializer(ContributionModSerializer):
return super().save(**kwargs)
def filter_representation(self, representation):
def add_code(representation):
# This is inspired from the source of Django REST Framework
field = self._declared_fields["code"]
representation["code"] = field.to_representation(self.instance.source_code)
request = self.context["request"]
fields = request.query_params.get("fields", None)
if fields is not None:
fields = fields.split(",")
if "code" in fields:
add_code(representation)
else:
add_code(representation)
return super().filter_representation(representation)
# ----------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment