Skip to content

Instantly share code, notes, and snippets.

@anuj9196
Created August 14, 2018 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anuj9196/2b836ac6186aab3596bf168e8604ff05 to your computer and use it in GitHub Desktop.
Save anuj9196/2b836ac6186aab3596bf168e8604ff05 to your computer and use it in GitHub Desktop.
rest py
class ContactViewSet(viewsets.ModelViewSet):
"""
This viewset automatically provides `list`, `create`, `retrieve`,
`update` and `destroy` actions.
Additionally we also provide an extra `favourite`action
"""
serializer_class = ContactSerializer
permission_classes = (IsAuthenticated, AdminAuthenticationPermission,)
def get_queryset(self):
return Contact.objects.filter(user=self.request.user)
def perform_create(self, serializer):
serializer.save(user=self.request.user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment