Commit 63decf5e authored by Victoria Ahmadi's avatar Victoria Ahmadi
Browse files

Added coach_usernamer as a field in the serializer.

parent 6f4c591b
Pipeline #112672 failed with stages
in 2 minutes
...@@ -9,10 +9,11 @@ class SuggestedWorkoutSerializer(serializers.ModelSerializer): ...@@ -9,10 +9,11 @@ class SuggestedWorkoutSerializer(serializers.ModelSerializer):
suggested_exercise_instances = ExerciseInstanceSerializer( suggested_exercise_instances = ExerciseInstanceSerializer(
many=True, required=False) many=True, required=False)
suggested_workout_files = WorkoutFileSerializer(many=True, required=False) suggested_workout_files = WorkoutFileSerializer(many=True, required=False)
coach_username = serializers.SerializerMethodField()
class Meta: class Meta:
model = SuggestedWorkout model = SuggestedWorkout
fields = ['id', 'athlete', 'name', 'notes', 'date', fields = ['id', 'athlete', 'coach_username', 'name', 'notes', 'date',
'status', 'coach', 'suggested_exercise_instances', 'suggested_workout_files'] 'status', 'coach', 'suggested_exercise_instances', 'suggested_workout_files']
extra_kwargs = {"coach": {"read_only": True}} extra_kwargs = {"coach": {"read_only": True}}
...@@ -111,3 +112,14 @@ class SuggestedWorkoutSerializer(serializers.ModelSerializer): ...@@ -111,3 +112,14 @@ class SuggestedWorkoutSerializer(serializers.ModelSerializer):
files.all()[i].delete() files.all()[i].delete()
return instance return instance
def get_coach_username(self, obj):
"""Returns the owning user's username
Args:
obj (Workout): Current Workout
Returns:
str: Username of owner
"""
return obj.coach.username
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment