From cdd4db9b6ab8be0fba82f2d4ec7f6c86802669ea Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sat, 22 Apr 2023 13:03:43 +0800 Subject: [PATCH] Polished full_name for professor and student --- .../migrations/0002_professor_full_name.py | 19 ++++++++++++++ .../0003_remove_professor_full_name.py | 17 +++++++++++++ ...ofessor_full_name_professor_middle_name.py | 25 +++++++++++++++++++ infotech/professors/models.py | 8 +++--- .../migrations/0009_student_full_name.py | 19 ++++++++++++++ infotech/students/models.py | 7 +++--- infotech/students/serializers.py | 4 +-- 7 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 infotech/professors/migrations/0002_professor_full_name.py create mode 100644 infotech/professors/migrations/0003_remove_professor_full_name.py create mode 100644 infotech/professors/migrations/0004_professor_full_name_professor_middle_name.py create mode 100644 infotech/students/migrations/0009_student_full_name.py diff --git a/infotech/professors/migrations/0002_professor_full_name.py b/infotech/professors/migrations/0002_professor_full_name.py new file mode 100644 index 0000000..f49f378 --- /dev/null +++ b/infotech/professors/migrations/0002_professor_full_name.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2 on 2023-04-22 04:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('professors', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='professor', + name='full_name', + field=models.CharField(db_column='full_name', default=' ', max_length=80), + preserve_default=False, + ), + ] diff --git a/infotech/professors/migrations/0003_remove_professor_full_name.py b/infotech/professors/migrations/0003_remove_professor_full_name.py new file mode 100644 index 0000000..cf9ffd7 --- /dev/null +++ b/infotech/professors/migrations/0003_remove_professor_full_name.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2 on 2023-04-22 04:57 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('professors', '0002_professor_full_name'), + ] + + operations = [ + migrations.RemoveField( + model_name='professor', + name='full_name', + ), + ] diff --git a/infotech/professors/migrations/0004_professor_full_name_professor_middle_name.py b/infotech/professors/migrations/0004_professor_full_name_professor_middle_name.py new file mode 100644 index 0000000..d3327bd --- /dev/null +++ b/infotech/professors/migrations/0004_professor_full_name_professor_middle_name.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2 on 2023-04-22 05:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('professors', '0003_remove_professor_full_name'), + ] + + operations = [ + migrations.AddField( + model_name='professor', + name='full_name', + field=models.CharField(default=' ', max_length=120), + preserve_default=False, + ), + migrations.AddField( + model_name='professor', + name='middle_name', + field=models.CharField(default=' ', max_length=40), + preserve_default=False, + ), + ] diff --git a/infotech/professors/models.py b/infotech/professors/models.py index 052cc35..56f57f6 100644 --- a/infotech/professors/models.py +++ b/infotech/professors/models.py @@ -10,16 +10,18 @@ class Professor(models.Model): FEMALE = 'Female', first_name = models.CharField(max_length=40) + middle_name = models.CharField(max_length=40) last_name = models.CharField(max_length=40) + full_name = models.CharField(max_length=120) age = models.IntegerField() date_joined = models.DateTimeField(default=now, editable=False) gender = models.CharField(max_length=20, choices=Genders.choices) # subjects = models.ManyToManyField( # 'subjects.Subject', through='subjects.SubjectProfessor') - @property - def full_name(self): - return f"{self.first_name} {self.last_name}" + def save(self, *args, **kwargs): + self.full_name = f"{self.first_name} {self.last_name}" + super().save(*args, **kwargs) def __str__(self): return self.full_name diff --git a/infotech/students/migrations/0009_student_full_name.py b/infotech/students/migrations/0009_student_full_name.py new file mode 100644 index 0000000..dfa6620 --- /dev/null +++ b/infotech/students/migrations/0009_student_full_name.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2 on 2023-04-22 05:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('students', '0008_remove_student_schedules'), + ] + + operations = [ + migrations.AddField( + model_name='student', + name='full_name', + field=models.CharField(default=' ', max_length=120), + preserve_default=False, + ), + ] diff --git a/infotech/students/models.py b/infotech/students/models.py index 7ab0af2..50cf48f 100644 --- a/infotech/students/models.py +++ b/infotech/students/models.py @@ -21,6 +21,7 @@ class Student(models.Model): first_name = models.CharField(max_length=40) middle_name = models.CharField(max_length=40) last_name = models.CharField(max_length=40) + full_name = models.CharField(max_length=120) # age = models.IntegerField() sex = models.CharField(max_length=1, choices=SexChoices.choices) @@ -42,9 +43,9 @@ class Student(models.Model): current_semester = models.CharField( max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM) - @property - def full_name(self): - return f"{self.first_name} {self.last_name}" + def save(self, *args, **kwargs): + self.full_name = f"{self.first_name} {self.middle_name} {self.last_name}" + super().save(*args, **kwargs) def __str__(self): return self.full_name diff --git a/infotech/students/serializers.py b/infotech/students/serializers.py index 4363896..cfa1735 100644 --- a/infotech/students/serializers.py +++ b/infotech/students/serializers.py @@ -8,11 +8,11 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Student - fields = ['id', 'first_name', 'middle_name', 'last_name', + fields = ['id', 'full_name', 'first_name', 'middle_name', 'last_name', 'age', 'sex', 'birthdate', 'address', 'birthplace', 'mother_name', 'father_name', 'registrar_done', 'clearance_done', 'pta_done', 'year_level', 'current_semester' ] - read_only_fields = ['id'] + read_only_fields = ['id', 'full_name']