mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2024-11-17 06:29:26 +08:00
Move max_slots from subject to schedule
This commit is contained in:
parent
ba8bc60032
commit
d365284fad
6 changed files with 46 additions and 4 deletions
18
infotech/schedules/migrations/0005_schedule_max_slots.py
Normal file
18
infotech/schedules/migrations/0005_schedule_max_slots.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.2 on 2023-04-22 07:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('schedules', '0004_schedule_daytimes'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='schedule',
|
||||||
|
name='max_slots',
|
||||||
|
field=models.IntegerField(default=50),
|
||||||
|
),
|
||||||
|
]
|
|
@ -15,6 +15,7 @@ class Schedule(models.Model):
|
||||||
'daytimes.DayTime', related_name='DayTime_full_name', on_delete=models.CASCADE, null=True)
|
'daytimes.DayTime', related_name='DayTime_full_name', on_delete=models.CASCADE, null=True)
|
||||||
|
|
||||||
date_created = models.DateTimeField(default=now, editable=False)
|
date_created = models.DateTimeField(default=now, editable=False)
|
||||||
|
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}"
|
||||||
|
|
|
@ -24,6 +24,14 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Schedule
|
model = Schedule
|
||||||
fields = ('id', 'name', 'subject', 'daytimes', 'students_assigned',
|
fields = ('id', 'name', 'max_slots', 'subject', 'daytimes', 'students_assigned',
|
||||||
'professor', 'date_created')
|
'professor', 'date_created')
|
||||||
read_only_fields = ('id', 'date_created', 'name')
|
read_only_fields = ('id', 'date_created', 'name')
|
||||||
|
|
||||||
|
def validate(self, attrs):
|
||||||
|
students = attrs.get('students')
|
||||||
|
max_slots = attrs.get('max_slots')
|
||||||
|
if students.count() > max_slots:
|
||||||
|
raise serializers.ValidationError(
|
||||||
|
'Too many students for this subject')
|
||||||
|
return attrs
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 4.2 on 2023-04-22 07:00
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('subjects', '0007_delete_subjectstudent'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='subject',
|
||||||
|
name='max_slots',
|
||||||
|
),
|
||||||
|
]
|
|
@ -17,7 +17,6 @@ class Subject(models.Model):
|
||||||
|
|
||||||
name = models.CharField(max_length=40)
|
name = models.CharField(max_length=40)
|
||||||
code = models.CharField(max_length=20)
|
code = models.CharField(max_length=20)
|
||||||
max_slots = models.IntegerField(default=60)
|
|
||||||
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
||||||
semester = models.CharField(
|
semester = models.CharField(
|
||||||
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
||||||
|
|
|
@ -8,6 +8,5 @@ class SubjectSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Subject
|
model = Subject
|
||||||
fields = ('id', 'name', 'code',
|
fields = ('id', 'name', 'code', 'year_level', 'semester')
|
||||||
'max_slots', 'year_level', 'semester')
|
|
||||||
read_only_fields = ['id']
|
read_only_fields = ['id']
|
||||||
|
|
Loading…
Reference in a new issue