Skip to content

Instantly share code, notes, and snippets.

@bohde
Created April 13, 2011 15:52
Show Gist options
  • Save bohde/917804 to your computer and use it in GitHub Desktop.
Save bohde/917804 to your computer and use it in GitHub Desktop.
Dispatch to a different resource if the pk is 'self'
class UserResource(ModelResource):
def dispatch_detail(request, **kwargs):
if kwargs.get('pk') == "self":
# This assumes that self.is_authenticated sets request.user
self.is_authenticated(request)
kwargs['pk'] = request.user.id
return CurrentUserResource.dispatch_detail(request, **kwargs)
return super(UserResource, self).dispatch_detail(request, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment