mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2025-05-16 11:28:14 +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)
|
||||
|
||||
date_created = models.DateTimeField(default=now, editable=False)
|
||||
max_slots = models.IntegerField(default=50)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.name = f"{self.subject} : {self.professor}"
|
||||
|
|
|
@ -24,6 +24,14 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Schedule
|
||||
fields = ('id', 'name', 'subject', 'daytimes', 'students_assigned',
|
||||
fields = ('id', 'name', 'max_slots', 'subject', 'daytimes', 'students_assigned',
|
||||
'professor', 'date_created')
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue