diff --git a/core/migrations/0006_workoutroutine_exercises.py b/core/migrations/0006_workoutroutine_exercises.py new file mode 100644 index 0000000000000000000000000000000000000000..2bb09425178b1a11f568db443942d31d272848c9 --- /dev/null +++ b/core/migrations/0006_workoutroutine_exercises.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-05-16 22:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0005_alter_workoutroutine_workout_id'), + ] + + operations = [ + migrations.AddField( + model_name='workoutroutine', + name='exercises', + field=models.ManyToManyField(through='core.WorkoutExercise', to='core.exercise'), + ), + ] diff --git a/core/models.py b/core/models.py index ba8031ed81622aaab6901d5511d97213d0b114e2..7e4d380250f7a0d26e950ea820d57b6237ecb893 100644 --- a/core/models.py +++ b/core/models.py @@ -30,7 +30,7 @@ class WorkoutRoutine(models.Model): name = models.CharField(max_length = 30) description = models.CharField(max_length=50) total_completions = models.IntegerField(default=0) - + exercises = models.ManyToManyField(Exercise, through= 'WorkoutExercise') #A join table that links a workout routine with an exercise class WorkoutExercise(models.Model): diff --git a/core/templates/routine.html b/core/templates/routine.html index 17ce1cbdf4ec75987b5173ecce50ba5219cea4c7..9e6e5f19b95151eb3a07c0a845ef310bf77772a3 100644 --- a/core/templates/routine.html +++ b/core/templates/routine.html @@ -6,4 +6,7 @@ {% block page-content %} <div>{{routine.name}}</div> <div>Access the routine object and its properties by referencing 'routine'</div> +{% for exercise in exercises %} + <div>{{exercise.name}}</div> +{% endfor %} {% endblock %} \ No newline at end of file diff --git a/core/views.py b/core/views.py index 913f1313209e10429b64297d9ff19c5811b79380..65dc392bd952d10017cb86d9f7a9c10d668495a3 100644 --- a/core/views.py +++ b/core/views.py @@ -78,8 +78,14 @@ def routine(request, routine_id): if user is None: return redirect('home') + #fetch the routine using routine_id routine = WorkoutRoutine.objects.get(workout_id = routine_id) - return render(request, 'routine.html', context={'routine': routine}) + #now need to grab the exercises for that routine + #use the relation between workoutroutine and Exercise for this + exercises = routine.exercises.all() + context = {'routine':routine, 'exercises':exercises} + + return render(request, 'routine.html', context)