This commit is contained in:
Trey t
2023-07-27 19:07:35 -05:00
parent 6d68c59ac3
commit 67372cc8ab
9 changed files with 84 additions and 8 deletions

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.2.2 on 2023-07-26 22:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('exercise', '0007_exercise_estimated_rep_duration'),
]
operations = [
migrations.AddField(
model_name='exercise',
name='video_override',
field=models.CharField(blank=True, max_length=255, null=True),
),
]

View File

@@ -22,6 +22,7 @@ class Exercise(models.Model):
muscle_groups = models.CharField(null=True, blank=True, max_length=255)
synonyms = models.CharField(null=True, blank=True, max_length=255)
estimated_rep_duration = models.FloatField(null=True, blank=True, max_length=255)
video_override = models.CharField(null=True, blank=True, max_length=255)
class Meta:
ordering = ('name',)
@@ -30,7 +31,10 @@ class Exercise(models.Model):
return self.name + " --------- " + self.description
def video_url(self):
return "exercise_videos/" + self.name.replace(" ", "_") + ".mp4"
if self.video_override is not None and len(self.video_override) > 0:
return "exercise_videos/" + self.video_override
else:
return "exercise_videos/" + self.name.replace(" ", "_") + ".mp4"
def audio_url(self):
return "exercise_audio/" + self.name.replace(" ", "_") + ".m4a"

View File

@@ -12,10 +12,17 @@ from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import authentication_classes
from rest_framework.decorators import permission_classes
from django.core.cache import cache
# Create your views here.
@api_view(['GET'])
def all_exercises(request):
if 'all_exercises' in cache:
data = cache.get('all_exercises')
return Response(data=data, status=status.HTTP_200_OK)
users = Exercise.objects.all()
serializer = ExerciseSerializer(users, many=True)
return Response(data=serializer.data, status=status.HTTP_200_OK)
data = serializer.data
cache.set('all_exercises', data)
return Response(data=data, status=status.HTTP_200_OK)