Skip to content

Commit

Permalink
AnyBaseModelViewSet
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Nov 7, 2024
1 parent b7e603e commit 5848e30
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions codeforlife/serializers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
from ..views import BaseModelViewSet, ModelViewSet

RequestUser = t.TypeVar("RequestUser", bound=User)
AnyBaseModelViewSet = t.TypeVar(
"AnyBaseModelViewSet", bound=BaseModelViewSet
)
else:
RequestUser = t.TypeVar("RequestUser")
AnyBaseModelViewSet = t.TypeVar("AnyBaseModelViewSet")

AnyModel = t.TypeVar("AnyModel", bound=Model)
AnyBaseRequest = t.TypeVar("AnyBaseRequest", bound=BaseRequest)
Expand All @@ -31,12 +35,12 @@
class BaseModelSerializer(
BaseSerializer[AnyBaseRequest],
_ModelSerializer[AnyModel],
t.Generic[AnyBaseRequest, AnyModel],
t.Generic[AnyBaseRequest, AnyBaseModelViewSet, AnyModel],
):
"""Base model serializer for all model serializers."""

instance: t.Optional[AnyModel]
view: "BaseModelViewSet[AnyBaseRequest, AnyModel]"
view: AnyBaseModelViewSet

@property
def non_none_instance(self):
Expand All @@ -60,9 +64,11 @@ def to_representation(self, instance: AnyModel) -> DataDict:


class ModelSerializer(
BaseModelSerializer[Request[RequestUser], AnyModel],
BaseModelSerializer[
Request[RequestUser],
"ModelViewSet[RequestUser, AnyModel]",
AnyModel,
],
t.Generic[RequestUser, AnyModel],
):
"""Base model serializer for all model serializers."""

view: "ModelViewSet[RequestUser, AnyModel]" # type: ignore[assignment]

0 comments on commit 5848e30

Please sign in to comment.