Skip to content

Instantly share code, notes, and snippets.

@sankalpjonn
Last active March 21, 2021 01:05
Show Gist options
  • Select an option

  • Save sankalpjonn/d379367568fbe2b6cdd76b96a095c21d to your computer and use it in GitHub Desktop.

Select an option

Save sankalpjonn/d379367568fbe2b6cdd76b96a095c21d to your computer and use it in GitHub Desktop.
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticatedOrReadOnly
class RecipeViewSet(viewsets.ModelViewSet):
serializer_class = RecipeSerializer
permission_classes = (IsAuthenticatedOrReadOnly,)
def get_object(self):
return get_object_or_404(Recipe, id=self.request.query_params.get("id"))
def get_queryset(self):
return Recipe.objects.all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment