mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2024-11-17 06:29:26 +08:00
Moved year level endpoints to schedules
This commit is contained in:
parent
d365284fad
commit
97f8f6b9bc
6 changed files with 55 additions and 8 deletions
19
infotech/schedules/migrations/0006_schedule_year_level.py
Normal file
19
infotech/schedules/migrations/0006_schedule_year_level.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 07:21
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('schedules', '0005_schedule_max_slots'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='schedule',
|
||||
name='year_level',
|
||||
field=models.TextField(default='Placeholder Year Level'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -7,10 +7,13 @@ from django.utils.timezone import now
|
|||
class Schedule(models.Model):
|
||||
name = models.TextField()
|
||||
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
||||
year_level = models.TextField()
|
||||
|
||||
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)
|
||||
|
||||
daytimes = models.ForeignKey(
|
||||
'daytimes.DayTime', related_name='DayTime_full_name', on_delete=models.CASCADE, null=True)
|
||||
|
||||
|
@ -19,6 +22,7 @@ class Schedule(models.Model):
|
|||
|
||||
def save(self, *args, **kwargs):
|
||||
self.name = f"{self.subject} : {self.professor}"
|
||||
self.year_level = self.subject.year_level
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -24,14 +24,14 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Schedule
|
||||
fields = ('id', 'name', 'max_slots', 'subject', 'daytimes', 'students_assigned',
|
||||
fields = ('id', 'name', 'max_slots', 'subject', 'year_level', 'daytimes', 'students_assigned',
|
||||
'professor', 'date_created')
|
||||
read_only_fields = ('id', 'date_created', 'name')
|
||||
read_only_fields = ('id', 'date_created', 'name', 'year_level')
|
||||
|
||||
def validate(self, attrs):
|
||||
students = attrs.get('students')
|
||||
max_slots = attrs.get('max_slots')
|
||||
if students.count() > max_slots:
|
||||
if students and students.count() > max_slots:
|
||||
raise serializers.ValidationError(
|
||||
'Too many students for this subject')
|
||||
return attrs
|
||||
|
|
|
@ -9,4 +9,8 @@ router.register(r'schedules', views.ScheduleViewSet)
|
|||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
path('first_year_schedules/', views.FirstYearScheduleViewSet.as_view()),
|
||||
path('second_year_subjects/', views.SecondYearScheduleViewSet.as_view()),
|
||||
path('third_year_schedules/', views.ThirdYearScheduleViewSet.as_view()),
|
||||
path('fourth_year_schedules/', views.FourthYearScheduleViewSet.as_view()),
|
||||
]
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.shortcuts import render
|
|||
|
||||
# Create your views here.
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import viewsets
|
||||
from rest_framework import viewsets, generics
|
||||
from .serializers import ScheduleSerializer
|
||||
from .models import Schedule, StudentSchedule
|
||||
|
||||
|
@ -11,3 +11,27 @@ class ScheduleViewSet(viewsets.ModelViewSet):
|
|||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ScheduleSerializer
|
||||
queryset = Schedule.objects.all()
|
||||
|
||||
|
||||
class FirstYearScheduleViewSet(generics.ListAPIView):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ScheduleSerializer
|
||||
queryset = Schedule.objects.filter(year_level='1st Year')
|
||||
|
||||
|
||||
class SecondYearScheduleViewSet(generics.ListAPIView):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ScheduleSerializer
|
||||
queryset = Schedule.objects.filter(year_level='2nd Year')
|
||||
|
||||
|
||||
class ThirdYearScheduleViewSet(generics.ListAPIView):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ScheduleSerializer
|
||||
queryset = Schedule.objects.filter(year_level='3rd Year')
|
||||
|
||||
|
||||
class FourthYearScheduleViewSet(generics.ListAPIView):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ScheduleSerializer
|
||||
queryset = Schedule.objects.filter(year_level='4th Year')
|
||||
|
|
|
@ -8,8 +8,4 @@ router.register(r'subjects', views.SubjectViewSet)
|
|||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
path('first_year_subjects/', views.FirstYearSubjectViewSet.as_view()),
|
||||
path('second_year_subjects/', views.SecondYearSubjectViewSet.as_view()),
|
||||
path('third_year_subjects/', views.ThirdYearSubjectViewSet.as_view()),
|
||||
path('fourth_year_subjects/', views.FourthYearSubjectViewSet.as_view()),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue