WIP
This commit is contained in:
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
@@ -26,7 +26,7 @@ class Exercise(models.Model):
|
|||||||
ordering = ('name',)
|
ordering = ('name',)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name + ":" + self.description
|
return self.name + " --------- " + self.description
|
||||||
|
|
||||||
def video_url(self):
|
def video_url(self):
|
||||||
return "exercise_videos/" + self.name.replace(" ", "_") + ".mp4"
|
return "exercise_videos/" + self.name.replace(" ", "_") + ".mp4"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from django.contrib import admin
|
|||||||
from .models import *
|
from .models import *
|
||||||
from exercise.models import Exercise
|
from exercise.models import Exercise
|
||||||
from import_export.admin import ImportExportModelAdmin
|
from import_export.admin import ImportExportModelAdmin
|
||||||
|
from superset.models import Superset
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
class WorkoutExerciseInline(admin.StackedInline):
|
class WorkoutExerciseInline(admin.StackedInline):
|
||||||
@@ -9,11 +10,16 @@ class WorkoutExerciseInline(admin.StackedInline):
|
|||||||
ordering = ("pk",)
|
ordering = ("pk",)
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
class SupersetInline(admin.StackedInline):
|
||||||
|
model = Superset
|
||||||
|
ordering = ("pk",)
|
||||||
|
extra = 0
|
||||||
|
|
||||||
@admin.register(Workout)
|
@admin.register(Workout)
|
||||||
class WorkoutAdmin(ImportExportModelAdmin):
|
class WorkoutAdmin(ImportExportModelAdmin):
|
||||||
list_display = ("name", "description", "registered_user", "created_at", "updated_at")
|
list_display = ("name", "description", "registered_user", "created_at", "updated_at")
|
||||||
inlines = [
|
inlines = [
|
||||||
WorkoutExerciseInline,
|
SupersetInline,
|
||||||
]
|
]
|
||||||
|
|
||||||
@admin.register(WorkoutExercise)
|
@admin.register(WorkoutExercise)
|
||||||
|
|||||||
@@ -60,37 +60,53 @@ def add_workout(request):
|
|||||||
return Response(status=status.HTTP_400_BAD_REQUEST)
|
return Response(status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
# exercise_data = dict(request.POST)["exercise_data"]
|
# exercise_data = dict(request.POST)["exercise_data"]
|
||||||
exercise_data = request.data["exercise_data"]
|
exercise_data = request.data["supersets"]
|
||||||
|
|
||||||
if exercise_data is None:
|
if exercise_data is None:
|
||||||
return Response({"exercise_data": [ "missing" ] }, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"supersets": [ "missing" ] }, status=status.HTTP_400_BAD_REQUEST)
|
||||||
if len(exercise_data) < 1:
|
if len(exercise_data) < 1:
|
||||||
return Response({"exercise_data": [ "empty" ] }, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"supersets": [ "empty" ] }, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
serializer = POSTCompleteWorkoutSerializer(data=request.data)
|
serializer = POSTCompleteWorkoutSerializer(data=request.data)
|
||||||
|
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
new_obj = serializer.save(registered_user=registered_user)
|
workout = serializer.save(registered_user=registered_user)
|
||||||
new_obj.save()
|
workout.save()
|
||||||
|
|
||||||
for data in exercise_data:
|
for superset in exercise_data:
|
||||||
print(data)
|
name = superset["name"]
|
||||||
id = data["id"]
|
rounds = superset["rounds"]
|
||||||
if id is None:
|
exercises = superset["exercises"]
|
||||||
continue
|
superset_order = superset["order"]
|
||||||
|
|
||||||
exercise = Exercise.objects.get(pk=id)
|
superset = Superset.objects.create(
|
||||||
completed_workout = WorkoutExercise.objects.create(
|
workout=workout,
|
||||||
workout=new_obj,
|
name=name,
|
||||||
exercise=exercise
|
rounds=rounds,
|
||||||
|
order=superset_order
|
||||||
)
|
)
|
||||||
if "weight" in data:
|
superset.save()
|
||||||
completed_workout.weight = data["weight"]
|
|
||||||
if "reps" in data:
|
for exercise in exercises:
|
||||||
completed_workout.reps = data["reps"]
|
exercise_id = exercise["id"]
|
||||||
if "duration" in data:
|
exercise_obj = Exercise.objects.get(pk=exercise_id)
|
||||||
completed_workout.duration = data["duration"]
|
order = exercise["order"]
|
||||||
completed_workout.save()
|
|
||||||
|
supersetExercise = SupersetExercise.objects.create(
|
||||||
|
superset=superset,
|
||||||
|
exercise=exercise_obj,
|
||||||
|
order=order
|
||||||
|
)
|
||||||
|
|
||||||
|
if "weight" in exercise:
|
||||||
|
supersetExercise.weight = exercise["weight"]
|
||||||
|
if "reps" in exercise:
|
||||||
|
supersetExercise.reps = exercise["reps"]
|
||||||
|
if "duration" in exercise:
|
||||||
|
supersetExercise.duration = exercise["duration"]
|
||||||
|
supersetExercise.save()
|
||||||
|
|
||||||
|
superset_order += 1
|
||||||
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
|
|||||||
Reference in New Issue
Block a user