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