mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2024-11-16 22:19:25 +08:00
Added semester to schedules model
This commit is contained in:
parent
97f8f6b9bc
commit
bda623a5de
4 changed files with 29 additions and 4 deletions
19
infotech/schedules/migrations/0007_schedule_semester.py
Normal file
19
infotech/schedules/migrations/0007_schedule_semester.py
Normal file
|
@ -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,
|
||||||
|
),
|
||||||
|
]
|
|
@ -8,7 +8,7 @@ class Schedule(models.Model):
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
||||||
year_level = models.TextField()
|
year_level = models.TextField()
|
||||||
|
semester = models.TextField()
|
||||||
students_assigned = models.ManyToManyField(
|
students_assigned = models.ManyToManyField(
|
||||||
'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule')
|
'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule')
|
||||||
professor = models.OneToOneField(
|
professor = models.OneToOneField(
|
||||||
|
@ -21,8 +21,9 @@ class Schedule(models.Model):
|
||||||
max_slots = models.IntegerField(default=50)
|
max_slots = models.IntegerField(default=50)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
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.year_level = self.subject.year_level
|
||||||
|
self.semester = self.subject.semester
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -24,9 +24,10 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Schedule
|
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')
|
'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):
|
def validate(self, attrs):
|
||||||
students = attrs.get('students')
|
students = attrs.get('students')
|
||||||
|
|
|
@ -17,21 +17,25 @@ class FirstYearScheduleViewSet(generics.ListAPIView):
|
||||||
# permission_classes = [IsAuthenticated]
|
# permission_classes = [IsAuthenticated]
|
||||||
serializer_class = ScheduleSerializer
|
serializer_class = ScheduleSerializer
|
||||||
queryset = Schedule.objects.filter(year_level='1st Year')
|
queryset = Schedule.objects.filter(year_level='1st Year')
|
||||||
|
lookup_field = 'semester'
|
||||||
|
|
||||||
|
|
||||||
class SecondYearScheduleViewSet(generics.ListAPIView):
|
class SecondYearScheduleViewSet(generics.ListAPIView):
|
||||||
# permission_classes = [IsAuthenticated]
|
# permission_classes = [IsAuthenticated]
|
||||||
serializer_class = ScheduleSerializer
|
serializer_class = ScheduleSerializer
|
||||||
queryset = Schedule.objects.filter(year_level='2nd Year')
|
queryset = Schedule.objects.filter(year_level='2nd Year')
|
||||||
|
lookup_field = 'semester'
|
||||||
|
|
||||||
|
|
||||||
class ThirdYearScheduleViewSet(generics.ListAPIView):
|
class ThirdYearScheduleViewSet(generics.ListAPIView):
|
||||||
# permission_classes = [IsAuthenticated]
|
# permission_classes = [IsAuthenticated]
|
||||||
serializer_class = ScheduleSerializer
|
serializer_class = ScheduleSerializer
|
||||||
queryset = Schedule.objects.filter(year_level='3rd Year')
|
queryset = Schedule.objects.filter(year_level='3rd Year')
|
||||||
|
lookup_field = 'semester'
|
||||||
|
|
||||||
|
|
||||||
class FourthYearScheduleViewSet(generics.ListAPIView):
|
class FourthYearScheduleViewSet(generics.ListAPIView):
|
||||||
# permission_classes = [IsAuthenticated]
|
# permission_classes = [IsAuthenticated]
|
||||||
serializer_class = ScheduleSerializer
|
serializer_class = ScheduleSerializer
|
||||||
queryset = Schedule.objects.filter(year_level='4th Year')
|
queryset = Schedule.objects.filter(year_level='4th Year')
|
||||||
|
lookup_field = 'semester'
|
||||||
|
|
Loading…
Reference in a new issue