I want to work with 'start' param in permissions.py How I can take it ? My model
class Quiz(models.Model) :
title = models.CharField(max_length=50)
start = models.DateTimeField(default="2021-10-10")
end = models.DateTimeField(default="2021-10-11")
description = models.CharField(max_length=250)
permissions.py
from rest_framework import permissions
class IsTimeNotDefined(permissions.BasePermission) :
def has_permission(self, request, view):
if request.method in permissions.SAFE_METHODS:
return False
return False
CodePudding user response:
Use has_object_permission
instead of has_permission
.
Not that it only works for object-level actions like retrieve
, update
and destroy
. Not list
and create
.
def has_object_permission(self, request, view, obj):
obj.start