Skip to content

Commit

Permalink
base model serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Jan 20, 2024
1 parent af5603a commit 6d9e1fb
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
6 changes: 6 additions & 0 deletions codeforlife/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
© Ocado Group
Created on 20/01/2024 at 11:19:12(+00:00).
"""

from .base import *
21 changes: 21 additions & 0 deletions codeforlife/serializers/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
© Ocado Group
Created on 20/01/2024 at 11:19:24(+00:00).
Base model serializers.
"""

import typing as t

from django.db.models import Model
from rest_framework.serializers import ModelSerializer as _ModelSerializer

AnyModel = t.TypeVar("AnyModel", bound=Model)


class ModelSerializer(_ModelSerializer[AnyModel], t.Generic[AnyModel]):
"""Base model serializer for all model serializers."""

# pylint: disable-next=useless-parent-delegation
def update(self, instance, validated_data: t.Dict[str, t.Any]):
return super().update(instance, validated_data)
8 changes: 6 additions & 2 deletions codeforlife/user/serializers/klass.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from rest_framework import serializers
"""
© Ocado Group
Created on 20/01/2024 at 11:28:29(+00:00).
"""

from ...serializers import ModelSerializer
from ..models import Class


# pylint: disable-next=missing-class-docstring
class ClassSerializer(serializers.ModelSerializer[Class]):
class ClassSerializer(ModelSerializer[Class]):
# pylint: disable-next=missing-class-docstring,too-few-public-methods
class Meta:
model = Class
Expand Down
8 changes: 6 additions & 2 deletions codeforlife/user/serializers/school.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from rest_framework import serializers
"""
© Ocado Group
Created on 20/01/2024 at 11:28:19(+00:00).
"""

from ...serializers import ModelSerializer
from ..models import School


# pylint: disable-next=missing-class-docstring
class SchoolSerializer(serializers.ModelSerializer[School]):
class SchoolSerializer(ModelSerializer[School]):
# pylint: disable-next=missing-class-docstring,too-few-public-methods
class Meta:
model = School
Expand Down
8 changes: 6 additions & 2 deletions codeforlife/user/serializers/student.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from rest_framework import serializers
"""
© Ocado Group
Created on 20/01/2024 at 11:27:56(+00:00).
"""

from ...serializers import ModelSerializer
from ..models import Student


# pylint: disable-next=missing-class-docstring
class StudentSerializer(serializers.ModelSerializer[Student]):
class StudentSerializer(ModelSerializer[Student]):
# pylint: disable-next=missing-class-docstring,too-few-public-methods
class Meta:
model = Student
Expand Down
8 changes: 6 additions & 2 deletions codeforlife/user/serializers/teacher.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from rest_framework import serializers
"""
© Ocado Group
Created on 20/01/2024 at 11:27:43(+00:00).
"""

from ...serializers import ModelSerializer
from ..models import Teacher


# pylint: disable-next=missing-class-docstring
class TeacherSerializer(serializers.ModelSerializer[Teacher]):
class TeacherSerializer(ModelSerializer[Teacher]):
# pylint: disable-next=missing-class-docstring,too-few-public-methods
class Meta:
model = Teacher
Expand Down
5 changes: 2 additions & 3 deletions codeforlife/user/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
Created on 19/01/2024 at 11:06:00(+00:00).
"""

from rest_framework import serializers

from ...serializers import ModelSerializer
from ..models import User
from .student import StudentSerializer
from .teacher import TeacherSerializer


# pylint: disable-next=missing-class-docstring
class UserSerializer(serializers.ModelSerializer[User]):
class UserSerializer(ModelSerializer[User]):
student = StudentSerializer(
source="new_student",
read_only=True,
Expand Down

0 comments on commit 6d9e1fb

Please sign in to comment.