Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Action based permissions in Django Rest V3+

class ActivityViewSet(viewsets.ModelViewSet):
  queryset = Activity.objects.all()
  serializer_class = ActivitySerializer

  def get_permissions(self):
      """Set custom permissions for each action."""
      if self.action in ['update', 'partial_update', 'destroy', 'list']:
          self.permission_classes = [IsAuthenticated, ]
      elif self.action in ['create']:
          self.permission_classes = [AllowAny, ]
      return super().get_permissions()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Action #based #permissions #Django #Rest
ADD COMMENT
Topic
Name
4+8 =