Skip to content

Commit

Permalink
feat: change candidate representation from id to username
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-canon committed Jul 15, 2024
1 parent bad261a commit 98bb029
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions eox_nelp/pearson_vue/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,23 @@ def get_course(self, obj):
str or None: The string representation of the course if it exists, otherwise `None`.
"""
return str(obj.course) if obj.course else None

def to_representation(self, instance):
"""
Convert the object instance to its dictionary representation.
This method overrides the default `to_representation` method to include
the candidate's username in the serialized representation.
Args:
instance (object): The object instance being serialized.
Returns:
dict: A dictionary representation of the object instance, including
the candidate's username if a candidate is associated with the instance.
If no candidate is associated, the value will be None.
"""
representation = super().to_representation(instance)
representation["candidate"] = instance.candidate.username if instance.candidate else None

return representation

0 comments on commit 98bb029

Please sign in to comment.