Commit 392920b4 authored by Christopher Collin Løkken's avatar Christopher Collin Løkken 🛀
Browse files

Merge branch 'workoutrefactor' into 'master'


See merge request !11
parents 67ed6c38 3eb7442d
Pipeline #172961 failed with stages
in 1 minute and 4 seconds
"""Serializers for the workouts application
from numpy import add
from rest_framework import serializers
from rest_framework.serializers import HyperlinkedRelatedField
from workouts.models.workouts import Workout
......@@ -128,8 +129,6 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
Workout: Updated Workout instance
exercise_instances_data = validated_data.pop("exercise_instances")
exercise_instances = instance.exercise_instances = validated_data.get("name",
instance.notes = validated_data.get("notes", instance.notes)
......@@ -139,7 +138,16 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
# Handle ExerciseInstances
self.handle_exercise_instance(validated_data, instance)
# Handle WorkoutFiles
self.handle_workout_files(validated_data, instance)
return instance
def handle_exercise_instance(self, validated_data, instance):
exercise_instances_data = validated_data.pop("exercise_instances")
exercise_instances = instance.exercise_instances
# This updates existing exercise instances without adding or deleting object.
# zip() will yield n 2-tuples, where n is
# min(len(exercise_instance), len(exercise_instance_data))
......@@ -173,8 +181,7 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
# Handle WorkoutFiles
def handle_workout_files(self, validated_data, instance):
if "files" in validated_data:
files_data = validated_data.pop("files")
files = instance.files
......@@ -195,8 +202,6 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
for i in range(len(files_data), len(files.all())):
return instance
def get_owner_username(self, obj):
"""Returns the owning user's 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