Worked out API's
This commit is contained in:
0
classes/__init__.py
Normal file
0
classes/__init__.py
Normal file
BIN
classes/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
classes/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
classes/__pycache__/admin.cpython-310.pyc
Normal file
BIN
classes/__pycache__/admin.cpython-310.pyc
Normal file
Binary file not shown.
BIN
classes/__pycache__/apps.cpython-310.pyc
Normal file
BIN
classes/__pycache__/apps.cpython-310.pyc
Normal file
Binary file not shown.
BIN
classes/__pycache__/models.cpython-310.pyc
Normal file
BIN
classes/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
classes/__pycache__/serializers.cpython-310.pyc
Normal file
BIN
classes/__pycache__/serializers.cpython-310.pyc
Normal file
Binary file not shown.
BIN
classes/__pycache__/urls.cpython-310.pyc
Normal file
BIN
classes/__pycache__/urls.cpython-310.pyc
Normal file
Binary file not shown.
BIN
classes/__pycache__/views.cpython-310.pyc
Normal file
BIN
classes/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
5
classes/admin.py
Normal file
5
classes/admin.py
Normal 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
6
classes/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ClassesConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'classes'
|
||||
23
classes/migrations/0001_initial.py
Normal file
23
classes/migrations/0001_initial.py
Normal 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()),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
classes/migrations/__init__.py
Normal file
0
classes/migrations/__init__.py
Normal file
BIN
classes/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
BIN
classes/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
Binary file not shown.
BIN
classes/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
classes/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
10
classes/models.py
Normal file
10
classes/models.py
Normal 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
7
classes/serializers.py
Normal 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
3
classes/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
7
classes/urls.py
Normal file
7
classes/urls.py
Normal 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
14
classes/views.py
Normal 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"
|
||||
Reference in New Issue
Block a user