| 1 |
from rest_framework import viewsets |
| 2 |
from rest_framework_extensions.mixins import DetailSerializerMixin |
| 3 |
|
| 4 |
from .models import Comment |
| 5 |
from .serializers import CommentSerializer, CommentDetailSerializer |
| 6 |
|
| 7 |
|
| 8 |
class CommentViewSet(DetailSerializerMixin, viewsets.ReadOnlyModelViewSet): |
| 9 |
serializer_class = CommentSerializer |
| 10 |
serializer_detail_class = CommentDetailSerializer |
| 11 |
queryset = Comment.objects.all() |
| 12 |
|
| 13 |
|
| 14 |
class CommentWithoutDetailSerializerClassViewSet(DetailSerializerMixin, viewsets.ReadOnlyModelViewSet): |
| 15 |
serializer_class = CommentSerializer |
| 16 |
queryset = Comment.objects.all() |
| 17 |
|
| 18 |
|
| 19 |
class CommentWithIdTwoViewSet(DetailSerializerMixin, viewsets.ReadOnlyModelViewSet): |
| 20 |
serializer_class = CommentSerializer |
| 21 |
serializer_detail_class = CommentDetailSerializer |
| 22 |
queryset = Comment.objects.filter(id=2) |
| 23 |
|
| 24 |
|
| 25 |
class CommentWithIdTwoAndIdOneForDetailViewSet(DetailSerializerMixin, viewsets.ReadOnlyModelViewSet): |
| 26 |
serializer_class = CommentSerializer |
| 27 |
serializer_detail_class = CommentDetailSerializer |
| 28 |
queryset = Comment.objects.filter(id=2) |
| 29 |
queryset_detail = Comment.objects.filter(id=1) |
| 30 |
|
| 31 |
|
| 32 |
class CommentWithDetailSerializerAndNoArgsForGetQuerySetViewSet(DetailSerializerMixin, viewsets.ModelViewSet): |
| 33 |
""" |
| 34 |
For regression tests https://github.com/chibisov/drf-extensions/pull/24 |
| 35 |
""" |
| 36 |
serializer_class = CommentSerializer |
| 37 |
serializer_detail_class = CommentDetailSerializer |
| 38 |
queryset = Comment.objects.all() |
| 39 |
queryset_detail = Comment.objects.filter(id=1) |
| 40 |
|
| 41 |
def get_queryset(self): |
| 42 |
return super().get_queryset() |