init commit

This commit is contained in:
Trey t
2024-06-23 22:51:58 -05:00
commit ddf67a4fc5
315 changed files with 163458 additions and 0 deletions

0
equipment/__init__.py Normal file
View File

12
equipment/admin.py Normal file
View File

@@ -0,0 +1,12 @@
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from .models import *
# Register your models here.
@admin.register(Equipment)
class EquipmentAdmin(ImportExportModelAdmin):
list_display = ("name", "is_weight", "category",)
@admin.register(WorkoutEquipment)
class WorkoutEquipmentAdmin(ImportExportModelAdmin):
list_display = ("equipment", "exercise",)

6
equipment/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class EquipmentConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'equipment'

View File

@@ -0,0 +1,25 @@
# Generated by Django 4.2.2 on 2023-06-11 22:00
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Equipment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('is_weight', models.BooleanField(default=False)),
('category', models.CharField(blank=True, max_length=64, null=True)),
('name', models.CharField(blank=True, max_length=64, null=True)),
],
),
]

View File

@@ -0,0 +1,25 @@
# Generated by Django 4.2.2 on 2023-06-13 02:07
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('exercise', '0002_alter_exercise_options'),
('equipment', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='WorkoutEquipment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('equipment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='workout_exercise_workout', to='equipment.equipment')),
('exercise', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='workout_exercise_workout', to='exercise.exercise')),
],
),
]

View File

30
equipment/models.py Normal file
View File

@@ -0,0 +1,30 @@
from django.db import models
from exercise.models import Exercise
# Create your models here.
class Equipment(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
is_weight = models.BooleanField(default=False)
category = models.CharField(null=True, blank=True, max_length=64)
name = models.CharField(null=True, blank=True, max_length=64)
def __str__(self):
return self.category + " : " + self.name
class WorkoutEquipment(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
exercise = models.ForeignKey(
Exercise,
on_delete=models.CASCADE,
related_name='workout_exercise_workout'
)
equipment = models.ForeignKey(
Equipment,
on_delete=models.CASCADE,
related_name='workout_exercise_workout'
)
def __str__(self):
return self.exercise.name + " : " + self.equipment.name

18
equipment/serializers.py Normal file
View File

@@ -0,0 +1,18 @@
from rest_framework import serializers
from .models import *
class EquipmentSerializer(serializers.ModelSerializer):
class Meta:
model = Equipment
fields = '__all__'
class WorkoutEquipmentSerializer(serializers.ModelSerializer):
name = serializers.SerializerMethodField()
class Meta:
model = WorkoutEquipment
fields = '__all__'
def get_name(self, obj):
return obj.equipment.name

3
equipment/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

7
equipment/urls.py Normal file
View File

@@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('all/', views.all_equipment, name='all equipment'),
]

28
equipment/views.py Normal file
View File

@@ -0,0 +1,28 @@
from django.shortcuts import render
from .models import *
from .serializers import *
from django.shortcuts import render
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
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_equipment(request):
if 'all_equipment' in cache:
data = cache.get('all_equipment')
return Response(data=data, status=status.HTTP_200_OK)
users = Equipment.objects.all()
serializer = EquipmentSerializer(users, many=True)
data = serializer.data
cache.set('all_equipment', data, timeout=None)
return Response(data=data, status=status.HTTP_200_OK)