我正在尝试应用以下装饰器:
def has_folder_access(func):
def wrapper(request, *args, **kwargs):
user_id = get_user_id(kwargs['context']['request'])
folder_id = kwargs['data']['folder_id']
user = get_user(user_id)
if user.role == 'super_admin' and check_file_add_access(user.id, folder_id):
return func(request, *args, **kwargs)
else:
return serializers.ValidationError({'type': 'error',
'content': 'You do not have access to that folder.'})
return wrapper
到序列化器类:
@has_folder_access
class FileSerializer(serializers.ModelSerializer):
...
但我不断得到:
File "C:\Python37\lib\site-packages\rest_framework\utils\model_meta.py", line 35, in get_field_info
opts = model._meta.concrete_model._meta
AttributeError: 'FileViewSet' object has no attribute '_meta'
任何提示/想法为什么会发生这种情况?