From bda623a5dea90b5c5812ac4919b5f8ee459e5cff Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sat, 22 Apr 2023 15:43:09 +0800 Subject: [PATCH] Added semester to schedules model --- .../migrations/0007_schedule_semester.py | 19 +++++++++++++++++++ infotech/schedules/models.py | 5 +++-- infotech/schedules/serializers.py | 5 +++-- infotech/schedules/views.py | 4 ++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 infotech/schedules/migrations/0007_schedule_semester.py diff --git a/infotech/schedules/migrations/0007_schedule_semester.py b/infotech/schedules/migrations/0007_schedule_semester.py new file mode 100644 index 0000000..d20f219 --- /dev/null +++ b/infotech/schedules/migrations/0007_schedule_semester.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2 on 2023-04-22 07:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('schedules', '0006_schedule_year_level'), + ] + + operations = [ + migrations.AddField( + model_name='schedule', + name='semester', + field=models.TextField(default='Placeholder Semester'), + preserve_default=False, + ), + ] diff --git a/infotech/schedules/models.py b/infotech/schedules/models.py index f3601f1..c73a302 100644 --- a/infotech/schedules/models.py +++ b/infotech/schedules/models.py @@ -8,7 +8,7 @@ class Schedule(models.Model): name = models.TextField() subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE) year_level = models.TextField() - + semester = models.TextField() students_assigned = models.ManyToManyField( 'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule') professor = models.OneToOneField( @@ -21,8 +21,9 @@ class Schedule(models.Model): max_slots = models.IntegerField(default=50) def save(self, *args, **kwargs): - self.name = f"{self.subject} : {self.professor}" + self.name = f"{self.subject} : {self.professor} - {self.daytimes}" self.year_level = self.subject.year_level + self.semester = self.subject.semester super().save(*args, **kwargs) def __str__(self): diff --git a/infotech/schedules/serializers.py b/infotech/schedules/serializers.py index 8faa096..77c01de 100644 --- a/infotech/schedules/serializers.py +++ b/infotech/schedules/serializers.py @@ -24,9 +24,10 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Schedule - fields = ('id', 'name', 'max_slots', 'subject', 'year_level', 'daytimes', 'students_assigned', + fields = ('id', 'name', 'max_slots', 'subject', 'year_level', 'semester', 'daytimes', 'students_assigned', 'professor', 'date_created') - read_only_fields = ('id', 'date_created', 'name', 'year_level') + read_only_fields = ('id', 'date_created', 'name', + 'year_level', 'semester') def validate(self, attrs): students = attrs.get('students') diff --git a/infotech/schedules/views.py b/infotech/schedules/views.py index 9402ddc..f9527b1 100644 --- a/infotech/schedules/views.py +++ b/infotech/schedules/views.py @@ -17,21 +17,25 @@ class FirstYearScheduleViewSet(generics.ListAPIView): # permission_classes = [IsAuthenticated] serializer_class = ScheduleSerializer queryset = Schedule.objects.filter(year_level='1st Year') + lookup_field = 'semester' class SecondYearScheduleViewSet(generics.ListAPIView): # permission_classes = [IsAuthenticated] serializer_class = ScheduleSerializer queryset = Schedule.objects.filter(year_level='2nd Year') + lookup_field = 'semester' class ThirdYearScheduleViewSet(generics.ListAPIView): # permission_classes = [IsAuthenticated] serializer_class = ScheduleSerializer queryset = Schedule.objects.filter(year_level='3rd Year') + lookup_field = 'semester' class FourthYearScheduleViewSet(generics.ListAPIView): # permission_classes = [IsAuthenticated] serializer_class = ScheduleSerializer queryset = Schedule.objects.filter(year_level='4th Year') + lookup_field = 'semester'