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

creating custom permissions in django

class USCitizen(models.Model):
    # ...
    class Meta:
        permissions = (
            ("can_drive", "Can drive"),
            ("can_vote", "Can vote in elections"),
            ("can_drink", "Can drink alcohol"),
        )
Comment

PREVIOUS NEXT
Code Example
Python :: Install Python2 and Python 3 
Python :: list slicing in python 
Python :: python numpy delete column 
Python :: tuplein python 
Python :: sort a dataframe 
Python :: Creating lambda expressions in comprehension list 
Python :: add column to dataframe pandas 
Python :: queue class python 
Python :: hash table python 
Python :: discord.py get client avatar 
Python :: create a virtual environment python 3 
Python :: syntax of ternary operator 
Python :: image to vector conversion function 
Python :: how to convert decimal to binary 
Python :: .pop python 
Python :: flask echo server 
Python :: InsertionSort 
Python :: randint without repitition 
Python :: python Entry default text 
Python :: boto3 upload to digital digitalocean folder 
Python :: how to make a window in python ursina 
Python :: rscript convert r to python script 
Python :: does pygame work on python 3.10.1 
Python :: python pytest use same tests for multiple modules 
Python :: labelling row in python 
Python :: converting from series to dataframe with tabulate 
Python :: fetch the appropriate version based on chrome python 
Python :: with statement python 3 files 
Python :: print numbers with underscores python 
Python :: python project pick text color according to background 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =