Skip to content

Instantly share code, notes, and snippets.

@hassanabidpk
Last active April 6, 2017 06:40
Show Gist options
  • Save hassanabidpk/eba5b8f604084e203c241e30956fad64 to your computer and use it in GitHub Desktop.
Save hassanabidpk/eba5b8f604084e203c241e30956fad64 to your computer and use it in GitHub Desktop.
views.py for Medium blog post
from .serializers import RestaurantSerializer
from rest_framework import status, permissions
from rest_framework import mixins, generics
class RestaurantList(mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView):
"""
List all restaurant, or create a restaurant
"""
#permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
parser_classes = (JSONParser, MultiPartParser, FormParser,)
queryset = Restaurant.objects.all()
serializer_class = RestaurantSerializer
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment