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 5848e30 commit 68df522
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions codeforlife/serializers/model_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,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 @@ -36,7 +40,7 @@
class BaseModelListSerializer(
BaseSerializer[AnyBaseRequest],
_ListSerializer[t.List[AnyModel]],
t.Generic[AnyBaseRequest, AnyModel],
t.Generic[AnyBaseRequest, AnyBaseModelViewSet, AnyModel],
):
"""Base model list serializer for all model list serializers.
Expand All @@ -57,7 +61,7 @@ class Meta:

instance: t.Optional[t.List[AnyModel]]
batch_size: t.Optional[int] = None
view: "BaseModelViewSet[AnyBaseRequest, AnyModel]"
view: AnyBaseModelViewSet

@property
def non_none_instance(self):
Expand Down Expand Up @@ -185,7 +189,11 @@ def to_representation(self, instance: t.List[AnyModel]) -> t.List[DataDict]:


class ModelListSerializer(
BaseModelListSerializer[Request[RequestUser], AnyModel],
BaseModelListSerializer[
Request[RequestUser],
"ModelViewSet[RequestUser, AnyModel]",
AnyModel,
],
t.Generic[RequestUser, AnyModel],
):
"""Base model list serializer for all model list serializers.
Expand All @@ -204,5 +212,3 @@ class Meta:
model = User
list_serializer_class = UserListSerializer
"""

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

0 comments on commit 68df522

Please sign in to comment.