diff --git a/infotech/subjects/migrations/0002_alter_subject_year_level.py b/infotech/subjects/migrations/0002_alter_subject_year_level.py new file mode 100644 index 0000000..9289269 --- /dev/null +++ b/infotech/subjects/migrations/0002_alter_subject_year_level.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-03-21 13:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('subjects', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='subject', + name='year_level', + field=models.CharField(choices=[('IU-Y1', '1st Year'), ('IU-Y2', '2nd Year'), ('IU-Y3', '3rd Year'), ('IU-Y4', '4th Year')], max_length=20), + ), + ] diff --git a/infotech/subjects/models.py b/infotech/subjects/models.py index 9d96b83..0fe52a3 100644 --- a/infotech/subjects/models.py +++ b/infotech/subjects/models.py @@ -4,6 +4,12 @@ from django.core.validators import MaxValueValidator, MinValueValidator class Subject(models.Model): + class YearLevels(models.TextChoices): + FIRST_YEAR = 'IU-Y1', '1st Year' + SECOND_YEAR = 'IU-Y2', '2nd Year' + THIRD_YEAR = 'IU-Y3', '3rd Year' + FOURTH_YEAR = 'IU-Y4', '4th Year' + name = models.CharField(max_length=40) enrolled_count = models.IntegerField( default=0, @@ -12,7 +18,7 @@ class Subject(models.Model): MinValueValidator(0) ]) max_slots = models.IntegerField(default=60) - year_level = models.CharField(max_length=20) + year_level = models.CharField(max_length=20, choices=YearLevels.choices) def __str__(self): return self.name diff --git a/infotech/subjects/serializers.py b/infotech/subjects/serializers.py index f730855..3970027 100644 --- a/infotech/subjects/serializers.py +++ b/infotech/subjects/serializers.py @@ -9,4 +9,4 @@ class SubjectSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Subject fields = ('id', 'name', 'enrolled_count', 'max_slots', 'year_level') - read_only_fields = ('id', 'max_slots') + read_only_fields = ('id',)