diff --git a/.gitignore b/.gitignore index 25e9be90..a6d9e34b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ node_modules # Generovane TypeScript typy pre FE *.ts + +StromBackend/ +.venv diff --git a/personal/serializers.py b/personal/serializers.py index 3fec5b52..89177100 100644 --- a/personal/serializers.py +++ b/personal/serializers.py @@ -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': { @@ -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')) @@ -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'], )