mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2025-05-16 11:28:14 +08:00
Polished full_name for professor and student
This commit is contained in:
parent
f9b585108e
commit
cdd4db9b6a
7 changed files with 91 additions and 8 deletions
19
infotech/students/migrations/0009_student_full_name.py
Normal file
19
infotech/students/migrations/0009_student_full_name.py
Normal file
|
@ -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,
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -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']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue