Skip to content
Snippets Groups Projects

Refactor update creation api

Merged Samuel GAIST requested to merge refactor_update_creation_api into master
All threads resolved!
1 file
+ 17
0
Compare changes
  • Side-by-side
  • Inline
@@ -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)
# ----------------------------------------------------------
Loading