From bb939198e50572c95065ecec47ab5a60375f0970 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Tue, 21 Mar 2023 21:59:09 +0800 Subject: [PATCH] Polish current semester choices on both student and subject --- .../0002_student_current_semester.py | 18 ++++++++++++++++++ infotech/students/models.py | 6 ++++++ infotech/students/serializers.py | 2 +- .../migrations/0003_subject_semester.py | 18 ++++++++++++++++++ infotech/subjects/models.py | 6 ++++++ infotech/subjects/serializers.py | 3 ++- 6 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 infotech/students/migrations/0002_student_current_semester.py create mode 100644 infotech/subjects/migrations/0003_subject_semester.py diff --git a/infotech/students/migrations/0002_student_current_semester.py b/infotech/students/migrations/0002_student_current_semester.py new file mode 100644 index 0000000..db78999 --- /dev/null +++ b/infotech/students/migrations/0002_student_current_semester.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-03-21 13:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('students', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='student', + name='current_semester', + field=models.CharField(choices=[('Sem-1', '1st Semester'), ('Sem-2', '2nd Semester')], default='Sem-1', max_length=20), + ), + ] diff --git a/infotech/students/models.py b/infotech/students/models.py index f8d659d..aa1b2e9 100644 --- a/infotech/students/models.py +++ b/infotech/students/models.py @@ -11,6 +11,10 @@ class Student(models.Model): THIRD_YEAR = 'IU-Y3', '3rd Year' FOURTH_YEAR = 'IU-Y4', '4th Year' + class Semesters(models.TextChoices): + FIRST_SEM = 'Sem-1', '1st Semester' + SECOND_SEM = 'Sem-2', '2nd Semester' + class SexChoices(models.TextChoices): MALE = 'M', 'Male' FEMALE = 'F', 'Female' @@ -35,6 +39,8 @@ class Student(models.Model): # enrolled_subjects = models.CharField(max_length=800) year_level = models.CharField(max_length=20, choices=YearLevels.choices) + current_semester = models.CharField( + max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM) def __str__(self): return self.name diff --git a/infotech/students/serializers.py b/infotech/students/serializers.py index c32698a..dbf2553 100644 --- a/infotech/students/serializers.py +++ b/infotech/students/serializers.py @@ -12,6 +12,6 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer): 'address', 'birthplace', 'mother_name', 'father_name', 'registrar_done', 'clearance_done', 'pta_done', - 'enrolled_subjects', 'year_level' + 'enrolled_subjects', 'year_level', 'current_semester' ] read_only_fields = ['id'] diff --git a/infotech/subjects/migrations/0003_subject_semester.py b/infotech/subjects/migrations/0003_subject_semester.py new file mode 100644 index 0000000..2540c85 --- /dev/null +++ b/infotech/subjects/migrations/0003_subject_semester.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-03-21 13:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('subjects', '0002_alter_subject_year_level'), + ] + + operations = [ + migrations.AddField( + model_name='subject', + name='semester', + field=models.CharField(choices=[('Sem-1', '1st Semester'), ('Sem-2', '2nd Semester')], default='Sem-1', max_length=20), + ), + ] diff --git a/infotech/subjects/models.py b/infotech/subjects/models.py index 0fe52a3..87af399 100644 --- a/infotech/subjects/models.py +++ b/infotech/subjects/models.py @@ -10,6 +10,10 @@ class Subject(models.Model): THIRD_YEAR = 'IU-Y3', '3rd Year' FOURTH_YEAR = 'IU-Y4', '4th Year' + class Semesters(models.TextChoices): + FIRST_SEM = 'Sem-1', '1st Semester' + SECOND_SEM = 'Sem-2', '2nd Semester' + name = models.CharField(max_length=40) enrolled_count = models.IntegerField( default=0, @@ -19,6 +23,8 @@ class Subject(models.Model): ]) max_slots = models.IntegerField(default=60) year_level = models.CharField(max_length=20, choices=YearLevels.choices) + semester = models.CharField( + max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM) def __str__(self): return self.name diff --git a/infotech/subjects/serializers.py b/infotech/subjects/serializers.py index 3970027..79e51c4 100644 --- a/infotech/subjects/serializers.py +++ b/infotech/subjects/serializers.py @@ -8,5 +8,6 @@ class SubjectSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Subject - fields = ('id', 'name', 'enrolled_count', 'max_slots', 'year_level') + fields = ('id', 'name', 'enrolled_count', + 'max_slots', 'year_level', 'semester') read_only_fields = ('id',)