Skip to content

Commit

Permalink
Added data in myprofile endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamín Mravec committed Nov 10, 2023
1 parent 2b7da9a commit 2d44a47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ node_modules

# Generovane TypeScript typy pre FE
*.ts

StromBackend/
.venv
15 changes: 11 additions & 4 deletions personal/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ def get_verbose_name(self, obj):
@ts_interface(context='personal')
class ProfileSerializer(serializers.ModelSerializer):
#grade_info = GradeSerializer(many=True)

grade = serializers.IntegerField()
grade_name = serializers.SerializerMethodField('get_grade_name')
school = SchoolProfileSerializer(many=False, read_only=True)
is_student = serializers.SerializerMethodField('get_is_student')
has_school = serializers.SerializerMethodField('get_has_school')
school_id = serializers.IntegerField()
email = serializers.EmailField(source='user.email')

class Meta:
model = Profile
fields = ['first_name', 'last_name', 'nickname', 'school',
fields = ['grade_name', 'id', 'email', 'first_name', 'last_name', 'nickname', 'school',
'phone', 'parent_phone', 'gdpr', 'grade', 'is_student', 'has_school', 'school_id']
read_only_fields = ['first_name', 'last_name',
read_only_fields = ['grade_name', 'id', 'first_name', 'last_name',
'email', 'is_student', 'has_school', 'school'] # 'year_of_graduation',
email = serializers.EmailField(source='user.email')

extra_kwargs = {
'grade': {
Expand All @@ -79,6 +81,11 @@ def get_is_student(self, obj):

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

def get_grade_name(self, obj):
return Grade.get_grade_by_year_of_graduation(
year_of_graduation=obj.year_of_graduation
).name

def update(self, instance, validated_data):
grade = Grade.objects.get(pk=validated_data.pop('grade'))
Expand All @@ -101,7 +108,7 @@ def create(self, validated_data):
year_of_graduation=grade.get_year_of_graduation_by_date(),
phone=validated_data['phone'],
parent_phone=validated_data['parent_phone'],
gdpr=validated_data['gdpr']
gdpr=validated_data['gdpr'],
)


Expand Down

0 comments on commit 2d44a47

Please sign in to comment.