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.
@@ -42,6 +42,8 @@ INSTALLED_APPS = [
|
|||||||
|
|
||||||
'api',
|
'api',
|
||||||
'student',
|
'student',
|
||||||
|
'classes',
|
||||||
|
'university',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|||||||
@@ -15,8 +15,11 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('student/', include("student.urls")),
|
||||||
|
path('classes/', include('classes.urls')),
|
||||||
|
path("university/", include('university.urls')),
|
||||||
]
|
]
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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"
|
||||||
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
django
|
||||||
|
django-admin
|
||||||
|
djangorestframework
|
||||||
|
environs
|
||||||
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.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from classes.models import Classes
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
class Student(models.Model):
|
class Student(models.Model):
|
||||||
w_number = models.IntegerField()
|
w_number = models.IntegerField()
|
||||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||||
classes = models.CharField(max_length = 200)
|
classes = models.ManyToManyField(Classes)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.user.username.capitalize()
|
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 django.shortcuts import render
|
||||||
|
from rest_framework import generics
|
||||||
|
from .models import Student
|
||||||
|
from .serializers import StudentSerializer
|
||||||
|
|
||||||
# Create your views here.
|
# 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"
|
||||||
0
university/__init__.py
Normal file
0
university/__init__.py
Normal file
BIN
university/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
university/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
university/__pycache__/admin.cpython-310.pyc
Normal file
BIN
university/__pycache__/admin.cpython-310.pyc
Normal file
Binary file not shown.
BIN
university/__pycache__/apps.cpython-310.pyc
Normal file
BIN
university/__pycache__/apps.cpython-310.pyc
Normal file
Binary file not shown.
BIN
university/__pycache__/models.cpython-310.pyc
Normal file
BIN
university/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
university/__pycache__/serializers.cpython-310.pyc
Normal file
BIN
university/__pycache__/serializers.cpython-310.pyc
Normal file
Binary file not shown.
BIN
university/__pycache__/urls.cpython-310.pyc
Normal file
BIN
university/__pycache__/urls.cpython-310.pyc
Normal file
Binary file not shown.
BIN
university/__pycache__/views.cpython-310.pyc
Normal file
BIN
university/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
7
university/admin.py
Normal file
7
university/admin.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from .models import University, Agreement, Section
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
admin.site.register(University)
|
||||||
|
admin.site.register(Agreement)
|
||||||
|
admin.site.register(Section)
|
||||||
6
university/apps.py
Normal file
6
university/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class UniversityConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'university'
|
||||||
39
university/migrations/0001_initial.py
Normal file
39
university/migrations/0001_initial.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Generated by Django 5.0.1 on 2024-06-10 02:49
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('classes', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Sections',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('area_name', models.CharField(max_length=200)),
|
||||||
|
('classes', models.ManyToManyField(to='classes.classes')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Agreements',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('major', models.CharField(max_length=200)),
|
||||||
|
('sections', models.ManyToManyField(to='university.sections')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='University',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=200)),
|
||||||
|
('agreements', models.ManyToManyField(to='university.agreements')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 5.0.1 on 2024-06-10 02:52
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('classes', '0001_initial'),
|
||||||
|
('university', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameModel(
|
||||||
|
old_name='Agreements',
|
||||||
|
new_name='Agreement',
|
||||||
|
),
|
||||||
|
migrations.RenameModel(
|
||||||
|
old_name='Sections',
|
||||||
|
new_name='Section',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.0.1 on 2024-06-10 03:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('university', '0002_rename_agreements_agreement_rename_sections_section'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='section',
|
||||||
|
name='number_of_required_courses',
|
||||||
|
field=models.IntegerField(default=1),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
0
university/migrations/__init__.py
Normal file
0
university/migrations/__init__.py
Normal file
BIN
university/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
BIN
university/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
university/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
university/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
25
university/models.py
Normal file
25
university/models.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from django.db import models
|
||||||
|
from classes.models import Classes
|
||||||
|
|
||||||
|
class Section(models.Model):
|
||||||
|
area_name = models.CharField(max_length=200)
|
||||||
|
number_of_required_courses = models.IntegerField()
|
||||||
|
classes = models.ManyToManyField(Classes)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.area_name
|
||||||
|
|
||||||
|
class Agreement(models.Model):
|
||||||
|
major = models.CharField(max_length=200)
|
||||||
|
sections = models.ManyToManyField(Section)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.major
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
class University(models.Model):
|
||||||
|
name = models.CharField(max_length=200)
|
||||||
|
agreements = models.ManyToManyField(Agreement)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.name
|
||||||
38
university/serializers.py
Normal file
38
university/serializers.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from .models import University, Agreement, Section
|
||||||
|
|
||||||
|
class UniversitySerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
agreements = serializers.SlugRelatedField(
|
||||||
|
many = True,
|
||||||
|
read_only = True,
|
||||||
|
slug_field="major"
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = University
|
||||||
|
fields = ["name", "agreements"]
|
||||||
|
|
||||||
|
class AgreementsSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
sections = serializers.SlugRelatedField(
|
||||||
|
many = True,
|
||||||
|
read_only = True,
|
||||||
|
slug_field = "area_name"
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Agreement
|
||||||
|
fields = ["major", "sections"]
|
||||||
|
|
||||||
|
class SectionsSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
classes = serializers.SlugRelatedField(
|
||||||
|
many = True,
|
||||||
|
read_only = True,
|
||||||
|
slug_field = "MJC_Class_Name"
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Section
|
||||||
|
fields = ["area_name", "number_of_required_courses", "classes"]
|
||||||
3
university/tests.py
Normal file
3
university/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
11
university/urls.py
Normal file
11
university/urls.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("all_universities/", views.UniversityListCreate.as_view(), name="university-view-createlist"),
|
||||||
|
path("all_agreements/", views.AgreementsListCreate.as_view(), name="sections-view-createlist"),
|
||||||
|
path("all_sections/", views.SectionsListCreate.as_view(), name="sections-view-createlist"),
|
||||||
|
path("<str:name>", views.UniversityRetrieveUpdateDestroy.as_view(), name="university-update"),
|
||||||
|
path("<str:name>/<str:major>", views.AgreementRetrieveUpdateDestroy.as_view(), name="agreement-update"),
|
||||||
|
path("<str:name>/<str:major>/<str:area_name>", views.SectionRetrieveUpdateDestroy.as_view(), name="section-update"),
|
||||||
|
]
|
||||||
32
university/views.py
Normal file
32
university/views.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
from rest_framework import generics
|
||||||
|
from .models import University, Agreement, Section
|
||||||
|
from .serializers import UniversitySerializer, AgreementsSerializer, SectionsSerializer
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
class UniversityListCreate(generics.ListCreateAPIView):
|
||||||
|
queryset = University.objects.all()
|
||||||
|
serializer_class = UniversitySerializer
|
||||||
|
|
||||||
|
class AgreementsListCreate(generics.ListCreateAPIView):
|
||||||
|
queryset = Agreement.objects.all()
|
||||||
|
serializer_class = AgreementsSerializer
|
||||||
|
|
||||||
|
class SectionsListCreate(generics.ListCreateAPIView):
|
||||||
|
queryset = Section.objects.all()
|
||||||
|
serializer_class = SectionsSerializer
|
||||||
|
|
||||||
|
class UniversityRetrieveUpdateDestroy(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
queryset = University.objects.all()
|
||||||
|
serializer_class = UniversitySerializer
|
||||||
|
lookup_field = "name"
|
||||||
|
|
||||||
|
class AgreementRetrieveUpdateDestroy(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
queryset = Agreement.objects.all()
|
||||||
|
serializer_class = AgreementsSerializer
|
||||||
|
lookup_field = "major"
|
||||||
|
|
||||||
|
class SectionRetrieveUpdateDestroy(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
queryset = Section.objects.all()
|
||||||
|
serializer_class = SectionsSerializer
|
||||||
|
lookup_field = "area_name"
|
||||||
Reference in New Issue
Block a user