2014-09-02 16:53:37 +04:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from rest_framework.views import APIView
|
2015-01-24 12:37:23 +03:00
|
|
|
from rest_framework.viewsets import ModelViewSet
|
2014-09-02 16:53:37 +04:00
|
|
|
from rest_framework import authentication
|
|
|
|
from rest_framework import renderers
|
|
|
|
from rest_framework.response import Response
|
2015-01-24 12:37:23 +03:00
|
|
|
from rest_framework.renderers import BrowsableAPIRenderer, JSONRenderer
|
|
|
|
from rest_framework.versioning import NamespaceVersioning
|
|
|
|
from .models import Foo, Bar
|
|
|
|
from .serializers import FooSerializer, BarSerializer
|
2014-09-02 16:53:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
class MockView(APIView):
|
|
|
|
|
|
|
|
authentication_classes = (authentication.SessionAuthentication,)
|
|
|
|
renderer_classes = (renderers.BrowsableAPIRenderer,)
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
return Response({'a': 1, 'b': 2, 'c': 3})
|
2015-01-24 12:37:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
class SerializerClassMixin(object):
|
|
|
|
def get_serializer_class(self):
|
|
|
|
# Get base name of serializer
|
|
|
|
self.request.version
|
|
|
|
return self.serializer_class
|
|
|
|
|
|
|
|
|
|
|
|
class FooViewSet(SerializerClassMixin, ModelViewSet):
|
|
|
|
versioning_class = NamespaceVersioning
|
|
|
|
model = Foo
|
|
|
|
queryset = Foo.objects.all()
|
|
|
|
serializer_class = FooSerializer
|
|
|
|
renderer_classes = (BrowsableAPIRenderer, JSONRenderer)
|
|
|
|
|
|
|
|
|
|
|
|
class BarViewSet(SerializerClassMixin, ModelViewSet):
|
|
|
|
model = Bar
|
|
|
|
queryset = Bar.objects.all()
|
|
|
|
serializer_class = BarSerializer
|
|
|
|
renderer_classes = (BrowsableAPIRenderer, )
|