Worked out API's
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
student/__pycache__/serializers.cpython-310.pyc
Normal file
BIN
student/__pycache__/serializers.cpython-310.pyc
Normal file
Binary file not shown.
BIN
student/__pycache__/urls.cpython-310.pyc
Normal file
BIN
student/__pycache__/urls.cpython-310.pyc
Normal file
Binary file not shown.
BIN
student/__pycache__/views.cpython-310.pyc
Normal file
BIN
student/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
@@ -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'),
|
||||
),
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
7
student/serializers.py
Normal 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
7
student/urls.py
Normal 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"),
|
||||
]
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user