我有一个 UserResource 定义为:
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
# No one is allowed to see all users
list_allowed_methods = []
detail_allowed_methods = ['get', 'put', 'patch']
# Hide staff
excludes = ('is_staff')
def apply_authorization_limits(self, request, object_list):
return object_list.filter(pk=request.user.pk)
def prepend_urls(self):
return [ url(r'^(?P<resource_name>%s)/$' % self._meta.resource_name, self.wrap_view('dispatch_detail'), name='api_dispatch_detail') ]
我希望 URI /user/ 只返回当前用户的详细信息,根本没有列表。我的解决方案给出了“在这个 uri 中找到了多个资源”错误,并且确实 dispatch_list 也在那里。我怎样才能让 /user/ 只返回和处理当前用户的详细信息?
谢谢