只是單一對象(細節)我有一個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 /用戶/只返回當前用戶的詳細信息,沒有列表的。我的解決方案提供了「在此uri中找到多個資源」的錯誤,並且確實也有dispatch_list。我如何擁有/用戶/返回並僅處理當前用戶的詳細信息?
感謝
你說的是在當前登錄用戶的? – 2013-03-27 10:05:53
是的,當前登錄的用戶 – Marin 2013-03-27 12:10:57