class ModelListCreateView(GetQuerysetMixin, generics.ListCreateAPIView):
queryset = get_objects_for_user(self.context['request'].user, 'model.view_model')
serializer_class = ModelSerializer
permission_classes = (permissions.IsAuthenticated,)
在上面的代码片段中,我试图仅查询给定用户应该看到的项目。我尝试了queryset = get_objects_for_user(request.user, 'model.view_model')
,但这不起作用,导致错误“请求”未定义。在谷歌搜索并尝试我现在拥有的内容后,我得到错误“自我”未定义。我也试图在其他权限之上实现django-guardian。
答案 0 :(得分:0)
如果您想访问请求对象,请覆盖>execSync@1.0.2 install C:\Users\UserName\AppData\Roaming\npm\node_modules\angular-cli\node_modules\execSync
node install.js
[execsync v1.0.2] Attempting to compile native extensions.
{ Error: spawn node-gyp ENOENT
at exports._errnoException (util.js:1007:11)
,而不是设置get_queryset
。
queryset