from django.contrib.auth.models import User
from project.api.models import Channel, Message
from project.api.permissions import IsOwnerOrReadOnly
from project.api.serializers import  ChannelSerializer, MessageSerializer, UserSerializer
from rest_framework import permissions, viewsets
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.reverse import reverse


@api_view(['GET'])
def api_root(request, format=None):
    return Response({
        'users': reverse('user-list', request=request, format=format),
        'messages': reverse('messages-list', request=request, format=format),
    })


class UserViewSet(viewsets.ModelViewSet):
    """
    This viewset automatically provides 'list' and 'detail' actions
    """
    queryset = User.objects.all()
    serializer_class = UserSerializer


class ChannelViewSet(viewsets.ModelViewSet):
    queryset = Channel.objects.all()
    serializer_class = ChannelSerializer


class MessageViewSet(viewsets.ModelViewSet):
    """
    This viewset automatically provides 'list', 'create', 'retrieve', 'update', and 'destory actions'

    Additionally we also provide an  'reply' action
    """
    queryset = Message.objects.all()
    serializer_class = MessageSerializer
    permission_class = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly,)

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)

@@ -277,17 +277,25 @@
 viewsets
+, mixins
 %0A
-
 from res
@@ -658,16 +658,345 @@
    %7D)%0A%0A%0A
+class CreateListRetrieveViewSet(mixins.CreateModelMixin, mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):%0A    %22%22%22%0A    A viewset that provides %60retrieve%60, %60create%60, and %60list%60 actions.%0A%0A    To use it, override the class and set the %60.queryset%60 and%0A    %60.serializer_class%60 attributes.%0A    %22%22%22%0A    pass%0A%0A%0A
 class Us
@@ -1329,38 +1329,42 @@
 sageViewSet(
-viewsets.Model
+CreateListRetrieve
 ViewSet):%0A  
@@ -1610,16 +1610,16 @@
 ializer%0A
+
     perm
@@ -1638,47 +1638,8 @@
  = (
-permissions.IsAuthenticatedOrReadOnly, 
 IsOw

Create custom view/list/retrieve viewset