Skip to content

Commit

Permalink
fix: extra_kwargs again
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Jan 29, 2024
1 parent d64ecf4 commit ebe5feb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
26 changes: 16 additions & 10 deletions codeforlife/user/serializers/klass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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},
}
3 changes: 1 addition & 2 deletions codeforlife/user/serializers/school.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -26,5 +26,4 @@ class Meta:
"id": {"read_only": True},
"name": {"read_only": True},
"country": {"read_only": True},
"uk_county": {"read_only": True},
}
12 changes: 8 additions & 4 deletions codeforlife/user/serializers/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -25,6 +31,4 @@ class Meta:
]
extra_kwargs = {
"id": {"read_only": True},
"klass": {"read_only": True},
"school": {"read_only": True},
}
12 changes: 8 additions & 4 deletions codeforlife/user/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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},
Expand Down

0 comments on commit ebe5feb

Please sign in to comment.