我正在尝试根据当前登录的用户进行过滤。我正在使用 ApiKeyAuthentication,据我所知,为了做到这一点,我需要使用 get_object_list。我遇到的问题是我似乎找不到任何方法来访问 get_object_list 中当前登录的用户。当我尝试调用 request.user 时,请求对象为空,我似乎无法找到解决问题的答案。
类部门资源(JSONResource):
class Meta:
resource_name = 'departments'
list_allowed_methods = ['get', 'put', 'post', 'delete']
detail_allowed_methods = ['get', 'put', 'post', 'delete']
authentication = ApiKeyAuthentication()
authorization = DjangoAuthorization()
def get_object_list(self, request):
permissions = department_permissions()
foo = []
foo.append(ApiObject(permissions.get_departments_linked_to_user(bundle.request.user)))
return foo
def obj_get_list(self, request=None, **kwargs):
return self.get_object_list(request)