我想在permissions.py中使用'start'参数我怎么能接受呢?我的模型
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
用has_object_permission
代替has_permission
。并不是说它只适用于对象级动作,如retrieve
,update
和destroy
。不是list
和create
。
def has_object_permission(self, request, view, obj):
obj.start