Worked out API's
This commit is contained in:
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