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