Skip to content

Commit

Permalink
Add user verbose_name
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed May 19, 2024
1 parent 112527b commit 3edb793
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion personal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def grade(self, value):
pk=value).get_year_of_graduation_by_date()

def __str__(self):
return str(self.user)
return f'{self.full_name()} ({self.user})'

def full_name(self):
return f'{self.first_name} {self.last_name}'
8 changes: 6 additions & 2 deletions personal/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ class ProfileSerializer(serializers.ModelSerializer):
has_school = serializers.SerializerMethodField('get_has_school')
school_id = serializers.IntegerField()
email = serializers.EmailField(source='user.email')
verbose_name = serializers.SerializerMethodField('get_verbose_name')

class Meta:
model = Profile
fields = ['grade_name', 'id', 'email', 'first_name', 'last_name', 'school',
'phone', 'parent_phone', 'grade', 'is_student', 'has_school', 'school_id']
'phone', 'parent_phone', 'grade', 'is_student', 'has_school', 'school_id', 'verbose_name']
read_only_fields = ['grade_name', 'id', 'first_name', 'last_name',
'email', 'is_student', 'has_school', 'school'] # 'year_of_graduation',
'email', 'is_student', 'has_school', 'school', 'verbose_name']

extra_kwargs = {
'grade': {
Expand All @@ -78,6 +79,9 @@ class Meta:
}
}

def get_verbose_name(self, obj):
return str(obj)

def get_is_student(self, obj):
return obj.school != School.objects.get(pk=1)

Expand Down

0 comments on commit 3edb793

Please sign in to comment.