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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.0.1 on 2024-06-09 22:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('classes', '0001_initial'),
('student', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='student',
name='classes',
),
migrations.AddField(
model_name='student',
name='classes',
field=models.ManyToManyField(to='classes.classes'),
),
]

View File

@@ -1,11 +1,12 @@
from django.db import models
from django.contrib.auth.models import User
from classes.models import Classes
# Create your models here.
class Student(models.Model):
w_number = models.IntegerField()
user = models.OneToOneField(User, on_delete=models.CASCADE)
classes = models.CharField(max_length = 200)
classes = models.ManyToManyField(Classes)
def __str__(self):
return self.user.username.capitalize()

7
student/serializers.py Normal file
View File

@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import Student
class StudentSerializer(serializers.ModelSerializer):
class Meta:
model = Student
fields = ["id", "user", "w_number", "classes"]

7
student/urls.py Normal file
View File

@@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path("all_students/", views.StudentListCreate.as_view(), name="student-view-createlist"),
path("<int:w_number>/", views.StudentRetrieveUpdateDestroy.as_view(), name="update"),
]

View File

@@ -1,3 +1,14 @@
from django.shortcuts import render
from rest_framework import generics
from .models import Student
from .serializers import StudentSerializer
# Create your views here.
class StudentListCreate(generics.ListCreateAPIView):
queryset = Student.objects.all()
serializer_class = StudentSerializer
class StudentRetrieveUpdateDestroy(generics.RetrieveUpdateDestroyAPIView):
queryset = Student.objects.all()
serializer_class = StudentSerializer
lookup_field = "w_number"