Commit 5ee58f7e authored by Håkon Finstad's avatar Håkon Finstad
Browse files

frontend

parent 2f7c145e
Pipeline #161812 passed with stage
in 23 seconds
......@@ -163,3 +163,5 @@ class RememberMe(models.Model):
def __str__(self):
return self.remember_me
......@@ -3,6 +3,7 @@
from rest_framework import serializers
from rest_framework.serializers import HyperlinkedRelatedField
from workouts.models import Workout, Exercise, ExerciseInstance, WorkoutFile, RememberMe
from django.contrib.auth import get_user_model
class ExerciseInstanceSerializer(serializers.HyperlinkedModelSerializer):
......@@ -64,6 +65,12 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
owner_username = serializers.SerializerMethodField()
exercise_instances = ExerciseInstanceSerializer(many=True, required=True)
files = WorkoutFileSerializer(many=True, required=False)
group_members = serializers.HyperlinkedRelatedField(
view_name='user-detail',
lookup_field='group_member',
many=True,
read_only=True
)
class Meta:
model = Workout
......
......@@ -186,16 +186,23 @@ async function generateWorkoutForm() {
}
submitForm.append("exercise_instances", JSON.stringify(exerciseInstances));
let rosterInputs = document.querySelectorAll('input[name="member"]');
let rosterInputs = formData.getAll("member");
console.log(rosterInputs);
let body = [];
let currentUser = await getCurrentUser();
body.push({
url: currentUser.url
});
for (let rosterInput of rosterInputs) {
if (!rosterInput.disabled && rosterInput.value) {
// get user
let response = await sendRequest("GET", `${HOST}/api/users/${rosterInput.value}/`);
if (response.ok) {
let member = await response.json();
body.push(member);
body.push({
url: member.url
});
} else {
let data = await response.json();
......@@ -204,9 +211,8 @@ async function generateWorkoutForm() {
}
}
}
console.log(body)
if(body.length != 0)
submitForm.append("group_members", JSON.stringify(body));
console.log(JSON.stringify(body));
submitForm.append("group_members", body);
// adding files
......
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