mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2024-11-17 06:29:26 +08:00
Initial transition to move relationships from subject to schedules
This commit is contained in:
parent
392bf195ae
commit
134df378c3
31 changed files with 334 additions and 22 deletions
|
@ -4,5 +4,7 @@ from django.urls import path, include
|
|||
urlpatterns = [
|
||||
path('', include('subjects.urls')),
|
||||
path('', include('students.urls')),
|
||||
path('', include('professors.urls')),
|
||||
path('', include('schedules.urls')),
|
||||
path('accounts/', include('accounts.urls')),
|
||||
]
|
||||
|
|
|
@ -44,7 +44,9 @@ INSTALLED_APPS = [
|
|||
'djoser',
|
||||
'subjects',
|
||||
'corsheaders',
|
||||
'students'
|
||||
'students',
|
||||
'professors',
|
||||
'schedules',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
0
infotech/professors/__init__.py
Normal file
0
infotech/professors/__init__.py
Normal file
6
infotech/professors/admin.py
Normal file
6
infotech/professors/admin.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.contrib import admin
|
||||
from .models import Professor
|
||||
|
||||
# Register your models here.
|
||||
|
||||
admin.site.register(Professor)
|
6
infotech/professors/apps.py
Normal file
6
infotech/professors/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ProfessorsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'professors'
|
26
infotech/professors/migrations/0001_initial.py
Normal file
26
infotech/professors/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 01:17
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Professor',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('first_name', models.CharField(max_length=40)),
|
||||
('last_name', models.CharField(max_length=40)),
|
||||
('age', models.IntegerField()),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
('gender', models.CharField(choices=[('Male', 'Male'), ('Female', 'Female')], max_length=20)),
|
||||
],
|
||||
),
|
||||
]
|
0
infotech/professors/migrations/__init__.py
Normal file
0
infotech/professors/migrations/__init__.py
Normal file
25
infotech/professors/models.py
Normal file
25
infotech/professors/models.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Professor(models.Model):
|
||||
|
||||
class Genders(models.TextChoices):
|
||||
MALE = 'Male',
|
||||
FEMALE = 'Female',
|
||||
|
||||
first_name = models.CharField(max_length=40)
|
||||
last_name = models.CharField(max_length=40)
|
||||
age = models.IntegerField()
|
||||
date_joined = models.DateTimeField(default=now, editable=False)
|
||||
gender = models.CharField(max_length=20, choices=Genders.choices)
|
||||
# subjects = models.ManyToManyField(
|
||||
# 'subjects.Subject', through='subjects.SubjectProfessor')
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
def __str__(self):
|
||||
return self.full_name
|
14
infotech/professors/serializers.py
Normal file
14
infotech/professors/serializers.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from rest_framework import serializers
|
||||
from .models import Professor
|
||||
from subjects.models import Subject
|
||||
|
||||
|
||||
class ProfessorSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date_joined = serializers.DateTimeField(
|
||||
format="%d-%m-%Y %I:%M%p", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Professor
|
||||
fields = ('id', 'first_name',
|
||||
'last_name', 'age', 'gender', 'date_joined')
|
||||
read_only_fields = ('id', 'date_joined')
|
3
infotech/professors/tests.py
Normal file
3
infotech/professors/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
13
infotech/professors/urls.py
Normal file
13
infotech/professors/urls.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from django.urls import include, path
|
||||
from rest_framework import routers
|
||||
from . import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'professors', views.ProfessorViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
|
||||
]
|
10
infotech/professors/views.py
Normal file
10
infotech/professors/views.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import viewsets
|
||||
from .serializers import ProfessorSerializer
|
||||
from .models import Professor
|
||||
|
||||
|
||||
class ProfessorViewSet(viewsets.ModelViewSet):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ProfessorSerializer
|
||||
queryset = Professor.objects.all().order_by('date_joined')
|
0
infotech/schedules/__init__.py
Normal file
0
infotech/schedules/__init__.py
Normal file
3
infotech/schedules/admin.py
Normal file
3
infotech/schedules/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
infotech/schedules/apps.py
Normal file
6
infotech/schedules/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SchedulesConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'schedules'
|
46
infotech/schedules/migrations/0001_initial.py
Normal file
46
infotech/schedules/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 02:49
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('subjects', '0006_remove_subject_students'),
|
||||
('professors', '0001_initial'),
|
||||
('students', '0004_student_enrolled_subjects'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Schedule',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date_created', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
('professor', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='Professor_last_name', to='professors.professor')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='StudentSchedule',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
('schedule', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='schedules.schedule')),
|
||||
('student_assigned', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='students.student')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='schedule',
|
||||
name='students_assigned',
|
||||
field=models.ManyToManyField(related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule', to='students.student'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='schedule',
|
||||
name='subject',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 02:53
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('professors', '0001_initial'),
|
||||
('schedules', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='schedule',
|
||||
name='professor',
|
||||
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='Professor_full_name', to='professors.professor'),
|
||||
),
|
||||
]
|
0
infotech/schedules/migrations/__init__.py
Normal file
0
infotech/schedules/migrations/__init__.py
Normal file
21
infotech/schedules/models.py
Normal file
21
infotech/schedules/models.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Schedule(models.Model):
|
||||
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
||||
students_assigned = models.ManyToManyField(
|
||||
'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule')
|
||||
professor = models.OneToOneField(
|
||||
'professors.Professor', related_name='Professor_full_name', on_delete=models.CASCADE)
|
||||
date_created = models.DateTimeField(default=now, editable=False)
|
||||
|
||||
|
||||
class StudentSchedule(models.Model):
|
||||
schedule = models.ForeignKey(
|
||||
'schedules.Schedule', on_delete=models.CASCADE)
|
||||
student_assigned = models.ForeignKey(
|
||||
'students.Student', on_delete=models.CASCADE)
|
||||
date_joined = models.DateTimeField(default=now, editable=False)
|
13
infotech/schedules/serializers.py
Normal file
13
infotech/schedules/serializers.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from rest_framework import serializers
|
||||
from .models import Schedule
|
||||
|
||||
|
||||
class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date_created = serializers.DateTimeField(
|
||||
format="%d-%m-%Y %I:%M%p", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Schedule
|
||||
fields = ('id', 'subject', 'students_assigned',
|
||||
'professor', 'date_created')
|
||||
read_only_fields = ('id', 'date_created')
|
3
infotech/schedules/tests.py
Normal file
3
infotech/schedules/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
13
infotech/schedules/urls.py
Normal file
13
infotech/schedules/urls.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from django.urls import include, path
|
||||
from rest_framework import routers
|
||||
from . import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'schedules', views.ScheduleViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
|
||||
]
|
13
infotech/schedules/views.py
Normal file
13
infotech/schedules/views.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import viewsets
|
||||
from .serializers import ScheduleSerializer
|
||||
from .models import Schedule
|
||||
|
||||
|
||||
class ScheduleViewSet(viewsets.ModelViewSet):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ScheduleSerializer
|
||||
queryset = Schedule.objects.all()
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 02:58
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('students', '0004_student_enrolled_subjects'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='student',
|
||||
name='enrolled_subjects',
|
||||
),
|
||||
]
|
|
@ -36,8 +36,8 @@ class Student(models.Model):
|
|||
clearance_done = models.BooleanField()
|
||||
pta_done = models.BooleanField()
|
||||
#
|
||||
enrolled_subjects = models.ManyToManyField(
|
||||
'subjects.Subject', through='subjects.SubjectStudent')
|
||||
# enrolled_subjects = models.ManyToManyField(
|
||||
# 'subjects.Subject', through='subjects.SubjectStudent')
|
||||
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
||||
current_semester = models.CharField(
|
||||
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
||||
|
|
|
@ -5,8 +5,6 @@ from subjects.models import Subject
|
|||
|
||||
|
||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||
enrolled_subjects = serializers.SlugRelatedField(
|
||||
queryset=Subject.objects.all(), many=True, slug_field='name', allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = Student
|
||||
|
@ -15,6 +13,6 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
|||
'address', 'birthplace',
|
||||
'mother_name', 'father_name',
|
||||
'registrar_done', 'clearance_done', 'pta_done',
|
||||
'enrolled_subjects', 'year_level', 'current_semester'
|
||||
'year_level', 'current_semester'
|
||||
]
|
||||
read_only_fields = ['id']
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 01:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subjects', '0004_remove_subject_enrolled_count_subjectstudent_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='subject',
|
||||
name='code',
|
||||
field=models.CharField(default='PLCHLDER-1', max_length=20),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='subject',
|
||||
name='semester',
|
||||
field=models.CharField(choices=[('1st Semester', 'First Sem'), ('2nd Semester', 'Second Sem')], default='1st Semester', max_length=20),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='subject',
|
||||
name='year_level',
|
||||
field=models.CharField(choices=[('1st Year', 'First Year'), ('2nd Year', 'Second Year'), ('3rd Year', 'Third Year'), ('4th Year', 'Fourth Year')], max_length=20),
|
||||
),
|
||||
]
|
17
infotech/subjects/migrations/0006_remove_subject_students.py
Normal file
17
infotech/subjects/migrations/0006_remove_subject_students.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 02:49
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subjects', '0005_subject_code_alter_subject_semester_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='subject',
|
||||
name='students',
|
||||
),
|
||||
]
|
17
infotech/subjects/migrations/0007_delete_subjectstudent.py
Normal file
17
infotech/subjects/migrations/0007_delete_subjectstudent.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 02:58
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('students', '0005_remove_student_enrolled_subjects'),
|
||||
('subjects', '0006_remove_subject_students'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='SubjectStudent',
|
||||
),
|
||||
]
|
|
@ -12,24 +12,15 @@ class Subject(models.Model):
|
|||
FOURTH_YEAR = '4th Year'
|
||||
|
||||
class Semesters(models.TextChoices):
|
||||
FIRST_SEM = 'Sem-1', '1st Semester'
|
||||
SECOND_SEM = 'Sem-2', '2nd Semester'
|
||||
FIRST_SEM = '1st Semester'
|
||||
SECOND_SEM = '2nd Semester'
|
||||
|
||||
name = models.CharField(max_length=40)
|
||||
code = models.CharField(max_length=20)
|
||||
max_slots = models.IntegerField(default=60)
|
||||
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
||||
semester = models.CharField(
|
||||
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
||||
|
||||
students = models.ManyToManyField(
|
||||
'students.Student', related_name='SubjectStudent_student_assigned', through='subjects.SubjectStudent')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class SubjectStudent(models.Model):
|
||||
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
||||
student_assigned = models.ForeignKey(
|
||||
'students.Student', on_delete=models.CASCADE, null=True)
|
||||
date_joined = models.DateTimeField(default=now, editable=False)
|
||||
|
|
|
@ -5,11 +5,9 @@ from students.models import Student
|
|||
|
||||
|
||||
class SubjectSerializer(serializers.HyperlinkedModelSerializer):
|
||||
students = serializers.SlugRelatedField(
|
||||
queryset=Student.objects.all(), many=True, slug_field='last_name', allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = Subject
|
||||
fields = ('id', 'name', 'students',
|
||||
fields = ('id', 'name',
|
||||
'max_slots', 'year_level', 'semester')
|
||||
read_only_fields = ('id',)
|
||||
read_only_fields = ['id']
|
||||
|
|
Loading…
Reference in a new issue