Commit 84002421 authored by Einar Uvsløkk's avatar Einar Uvsløkk
Browse files

Fix error in update methods

parent e85da022
......@@ -160,15 +160,15 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
num_data = len(data)
num_exercises = len(exercises)
if (diff := num_data - num_exercises) > 0:
if num_data > num_exercises:
for i in range(num_exercises, num_data):
ExerciseInstance.objects.create(
workout=workout,
**data[i],
)
elif diff < 0:
for exercise in exercises[:-diff]:
exercise.delete()
elif num_data < num_exercises:
for i in range(num_data, num_exercises):
exercises[i].delete()
def update_workout_files(self, workout, data):
"""Updates the files associated with a workout.
......@@ -187,16 +187,16 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
num_data = len(data)
num_files = len(files)
if (diff := num_data - num_files) > 0:
if num_data > num_files:
for i in range(num_files, num_data):
WorkoutFile.objects.create(
workout=workout,
owner=workout.owner,
**data[i],
)
elif diff < 0:
for file_obj in files[:-diff]:
file_obj.delete()
elif num_data < num_files:
for i in range(num_data, num_files):
files[i].delete()
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