From ebe5feb325a2d6b99c6f13e3c6817c653e570ba5 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Mon, 29 Jan 2024 12:08:50 +0000 Subject: [PATCH] fix: extra_kwargs again --- codeforlife/user/serializers/klass.py | 26 +++++++++++++++---------- codeforlife/user/serializers/school.py | 3 +-- codeforlife/user/serializers/student.py | 12 ++++++++---- codeforlife/user/serializers/user.py | 12 ++++++++---- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/codeforlife/user/serializers/klass.py b/codeforlife/user/serializers/klass.py index ba6c1357..4c99323d 100644 --- a/codeforlife/user/serializers/klass.py +++ b/codeforlife/user/serializers/klass.py @@ -11,19 +11,30 @@ # pylint: disable-next=missing-class-docstring class ClassSerializer(ModelSerializer[Class]): - id = serializers.CharField(source="access_code") + id = serializers.CharField( + source="access_code", + read_only=True, + ) read_classmates_data = serializers.BooleanField( - source="classmates_data_viewable" + source="classmates_data_viewable", + read_only=True, ) receive_requests_until = serializers.DateTimeField( - source="accept_requests_until" + source="accept_requests_until", + read_only=True, ) - teacher = serializers.IntegerField(source="teacher.id") + teacher = serializers.IntegerField( + source="teacher.id", + read_only=True, + ) - school = serializers.IntegerField(source="teacher.school.id") + school = serializers.IntegerField( + source="teacher.school.id", + read_only=True, + ) # pylint: disable-next=missing-class-docstring,too-few-public-methods class Meta: @@ -38,9 +49,4 @@ class Meta: ] extra_kwargs = { "name": {"read_only": True}, - "id": {"read_only": True}, - "teacher": {"read_only": True}, - "school": {"read_only": True}, - "read_classmates_data": {"read_only": True}, - "receive_requests_until": {"read_only": True}, } diff --git a/codeforlife/user/serializers/school.py b/codeforlife/user/serializers/school.py index 59a6f0d7..80db312d 100644 --- a/codeforlife/user/serializers/school.py +++ b/codeforlife/user/serializers/school.py @@ -11,7 +11,7 @@ # pylint: disable-next=missing-class-docstring class SchoolSerializer(ModelSerializer[School]): - uk_county = serializers.CharField(source="county") + uk_county = serializers.CharField(source="county", read_only=True) # pylint: disable-next=missing-class-docstring,too-few-public-methods class Meta: @@ -26,5 +26,4 @@ class Meta: "id": {"read_only": True}, "name": {"read_only": True}, "country": {"read_only": True}, - "uk_county": {"read_only": True}, } diff --git a/codeforlife/user/serializers/student.py b/codeforlife/user/serializers/student.py index 88df660c..d2187853 100644 --- a/codeforlife/user/serializers/student.py +++ b/codeforlife/user/serializers/student.py @@ -11,9 +11,15 @@ # pylint: disable-next=missing-class-docstring class StudentSerializer(ModelSerializer[Student]): - klass = serializers.CharField(source="class_field.access_code") + klass = serializers.CharField( + source="class_field.access_code", + read_only=True, + ) - school = serializers.IntegerField(source="class_field.teacher.school.id") + school = serializers.IntegerField( + source="class_field.teacher.school.id", + read_only=True, + ) # pylint: disable-next=missing-class-docstring,too-few-public-methods class Meta: @@ -25,6 +31,4 @@ class Meta: ] extra_kwargs = { "id": {"read_only": True}, - "klass": {"read_only": True}, - "school": {"read_only": True}, } diff --git a/codeforlife/user/serializers/user.py b/codeforlife/user/serializers/user.py index febac0a7..121597ca 100644 --- a/codeforlife/user/serializers/user.py +++ b/codeforlife/user/serializers/user.py @@ -11,9 +11,15 @@ # pylint: disable-next=missing-class-docstring class UserSerializer(ModelSerializer[User]): - student = StudentSerializer(source="new_student") + student = StudentSerializer( + source="new_student", + read_only=True, + ) - teacher = TeacherSerializer(source="new_teacher") + teacher = TeacherSerializer( + source="new_teacher", + read_only=True, + ) # pylint: disable-next=missing-class-docstring,too-few-public-methods class Meta: @@ -29,8 +35,6 @@ class Meta: "date_joined", ] extra_kwargs = { - "student": {"read_only": True}, - "teacher": {"read_only": True}, "id": {"read_only": True}, "first_name": {"read_only": True}, "last_name": {"read_only": True},