-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and apply custom ViewSet classes
- Loading branch information
Jon Walz
authored and
Jon Walz
committed
Feb 13, 2024
1 parent
e3eddfe
commit fb7c73b
Showing
6 changed files
with
32 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from rest_framework.viewsets import GenericViewSet | ||
from rest_framework import mixins as drf_mixins | ||
from rest_framework_json_api.views import AutoPrefetchMixin, PreloadIncludesMixin, RelatedMixin | ||
|
||
|
||
class _DrfJsonApiHelpers(AutoPrefetchMixin, PreloadIncludesMixin, RelatedMixin): | ||
pass | ||
|
||
class RetrieveOnlyViewSet(_DrfJsonApiHelpers, drf_mixins.RetrieveModelMixin, GenericViewSet): | ||
http_method_names = ["get", "head", "options"] | ||
|
||
|
||
class RetrieveWriteViewSet( | ||
_DrfJsonApiHelpers, | ||
drf_mixins.CreateModelMixin, | ||
drf_mixins.RetrieveModelMixin, | ||
drf_mixins.UpdateModelMixin, | ||
drf_mixins.DestroyModelMixin, | ||
GenericViewSet | ||
): | ||
http_method_names = ["get", "post", "patch", "delete", "head", "options"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
from rest_framework_json_api.views import ModelViewSet | ||
|
||
from .models import ConfiguredStorageAddon | ||
from .serializers import ConfiguredStorageAddonSerializer | ||
|
||
from addon_service.common.viewsets import RetrieveWriteViewSet | ||
|
||
class ConfiguredStorageAddonViewSet(ModelViewSet): | ||
class ConfiguredStorageAddonViewSet(RetrieveWriteViewSet): | ||
queryset = ConfiguredStorageAddon.objects.all() | ||
serializer_class = ConfiguredStorageAddonSerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from rest_framework_json_api.views import ModelViewSet | ||
from rest_framework_json_api.views import ReadOnlyViewSet | ||
|
||
from .models import ExternalStorageService | ||
from .serializers import ExternalStorageServiceSerializer | ||
|
||
|
||
class ExternalStorageServiceViewSet(ModelViewSet): | ||
class ExternalStorageServiceViewSet(ReadOnlyViewSet): | ||
queryset = ExternalStorageService.objects.all() | ||
serializer_class = ExternalStorageServiceSerializer | ||
# TODO: permissions_classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from rest_framework_json_api.views import ReadOnlyModelViewSet | ||
|
||
from .models import ResourceReference | ||
from .serializers import ResourceReferenceSerializer | ||
|
||
from addon_service.common.viewsets import RetrieveOnlyViewSet | ||
|
||
class ResourceReferenceViewSet(ReadOnlyModelViewSet): | ||
class ResourceReferenceViewSet(RetrieveOnlyViewSet): | ||
queryset = ResourceReference.objects.all() | ||
serializer_class = ResourceReferenceSerializer | ||
# TODO: permissions_classes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
from rest_framework_json_api.views import ReadOnlyModelViewSet | ||
|
||
from .models import UserReference | ||
from .serializers import UserReferenceSerializer | ||
|
||
from addon_service.common.viewsets import RetrieveOnlyViewSet | ||
|
||
class UserReferenceViewSet(ReadOnlyModelViewSet): | ||
class UserReferenceViewSet(RetrieveOnlyViewSet): | ||
queryset = UserReference.objects.all() | ||
serializer_class = UserReferenceSerializer | ||
# TODO: permissions_classes |