Skip to content

Commit 42451ad

Browse files
committed
make tests succeed with temporary workaround for polymorphic viewsets
1 parent 466f9e9 commit 42451ad

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

example/views.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
from rest_framework_json_api.filters import OrderingFilter, QueryParameterValidationFilter
1313
from rest_framework_json_api.pagination import JsonApiPageNumberPagination
1414
from rest_framework_json_api.utils import format_drf_errors
15-
from rest_framework_json_api.views import ModelViewSet, PreloadIncludesMixin, RelationshipView
15+
from rest_framework_json_api.views import (
16+
ModelViewSet,
17+
PreloadIncludesMixin,
18+
RelatedMixin,
19+
RelationshipView
20+
)
1621

1722
from example.models import Author, Blog, Comment, Company, Entry, Project, ProjectType
1823
from example.serializers import (
@@ -27,6 +32,9 @@
2732
ProjectTypeSerializer
2833
)
2934

35+
# AutoPreloadMixin
36+
37+
3038
HTTP_422_UNPROCESSABLE_ENTITY = 422
3139

3240

@@ -200,7 +208,18 @@ def get_queryset(self, *args, **kwargs):
200208
return super(CommentViewSet, self).get_queryset()
201209

202210

203-
class CompanyViewset(PreloadIncludesMixin, viewsets.ModelViewSet):
211+
class TestModelViewSet(PreloadIncludesMixin, RelatedMixin, viewsets.ModelViewSet):
212+
"""
213+
TODO: this is a temporary workaround since AutoPreloadMixin and PreloadIncludesMixin
214+
conflict with each other for polymorphic viewsets.
215+
See https://github.com/django-json-api/django-rest-framework-json-api/pull/643
216+
DJA's views.ModelViewSet has both AutoPreloadMixin and PreloadIncludesMixin.
217+
"""
218+
http_method_names = ['get', 'post', 'patch', 'delete', 'head', 'options']
219+
220+
221+
# class CompanyViewset(PreloadIncludesMixin, viewsets.ModelViewSet):
222+
class CompanyViewset(TestModelViewSet):
204223
queryset = Company.objects.all()
205224
serializer_class = CompanySerializer
206225
prefetch_for_includes = {

0 commit comments

Comments
 (0)