Worked out API's

This commit is contained in:
Lucas
2024-06-09 21:34:59 -07:00
parent 3fd16b4833
commit fc723d93fc
70 changed files with 337 additions and 2 deletions

0
classes/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
classes/admin.py Normal file
View File

@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Classes
# Register your models here.
admin.site.register(Classes)

6
classes/apps.py Normal file
View File

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

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.0.1 on 2024-06-09 22:23
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Classes',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('MJC_Class_Name', models.CharField(max_length=200)),
('Common_Class_Name', models.CharField(max_length=200)),
('MJC_Units', models.IntegerField()),
],
),
]

View File

10
classes/models.py Normal file
View File

@@ -0,0 +1,10 @@
from django.db import models
# Create your models here.
class Classes(models.Model):
MJC_Class_Name = models.CharField(max_length=200)
Common_Class_Name = models.CharField(max_length=200)
MJC_Units = models.IntegerField()
def __str__(self) -> str:
return self.MJC_Class_Name

7
classes/serializers.py Normal file
View File

@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import Classes
class ClassesSerializer(serializers.ModelSerializer):
class Meta:
model = Classes
fields = ["id", "MJC_Class_Name", "Common_Class_Name", "MJC_Units"]

3
classes/tests.py Normal file
View File

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

7
classes/urls.py Normal file
View File

@@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path("all_classes/", views.ClassesListCreate.as_view(), name="classes-view-createlist"),
path("<str:MJC_Class_Name>/", views.ClassesRetrieveUpdateDestroy.as_view(), name="classes_update")
]

14
classes/views.py Normal file
View File

@@ -0,0 +1,14 @@
from django.shortcuts import render
from rest_framework import generics
from .models import Classes
from .serializers import ClassesSerializer
# Create your views here.
class ClassesListCreate(generics.ListCreateAPIView):
queryset = Classes.objects.all()
serializer_class = ClassesSerializer
class ClassesRetrieveUpdateDestroy(generics.RetrieveUpdateDestroyAPIView):
queryset = Classes.objects.all()
serializer_class = ClassesSerializer
lookup_field = "MJC_Class_Name"