Search
 
SCRIPT & CODE EXAMPLE
 

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()
Comment

PREVIOUS NEXT
Code Example
Python :: Plotly set axes labels 
Python :: python create folder 
Python :: appending to a file in python 
Python :: how to use turtle in python in python 3.9 
Python :: visitor IP address django 
Python :: python file hidden 
Python :: dataframe column in list 
Python :: pythonwrite to file 
Python :: flask quickstart 
Python :: get file arg0 python 
Python :: flask-callable 
Python :: data series to datetime 
Python :: pip install python-telegram-bot 
Python :: measure time per line python 
Python :: km/h to mph python 
Python :: render django 
Python :: dictionary size in python 
Python :: end python program 
Python :: pandas return specific row 
Python :: pandas replace nan with mean 
Python :: python dictionary rename key 
Python :: python get parent directory 
Python :: flask template split string 
Python :: how to convert binary to text in python 
Python :: django login view 
Python :: python replace by dictionary 
Python :: doc2vec similarity 
Python :: how to convert into grayscale opencv 
Python :: run calc.exe inside python 
Python :: pathlib path get filename with extension 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =