|
12 | 12 | from rest_framework_json_api.filters import OrderingFilter, QueryParameterValidationFilter
|
13 | 13 | from rest_framework_json_api.pagination import JsonApiPageNumberPagination
|
14 | 14 | 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 | +) |
16 | 21 |
|
17 | 22 | from example.models import Author, Blog, Comment, Company, Entry, Project, ProjectType
|
18 | 23 | from example.serializers import (
|
|
27 | 32 | ProjectTypeSerializer
|
28 | 33 | )
|
29 | 34 |
|
| 35 | +# AutoPreloadMixin |
| 36 | + |
| 37 | + |
30 | 38 | HTTP_422_UNPROCESSABLE_ENTITY = 422
|
31 | 39 |
|
32 | 40 |
|
@@ -200,7 +208,18 @@ def get_queryset(self, *args, **kwargs):
|
200 | 208 | return super(CommentViewSet, self).get_queryset()
|
201 | 209 |
|
202 | 210 |
|
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): |
204 | 223 | queryset = Company.objects.all()
|
205 | 224 | serializer_class = CompanySerializer
|
206 | 225 |
|
|
0 commit comments