Skip to content

Instantly share code, notes, and snippets.

@jrm2k6
Last active December 23, 2015 19:39
Show Gist options
  • Select an option

  • Save jrm2k6/6683921 to your computer and use it in GitHub Desktop.

Select an option

Save jrm2k6/6683921 to your computer and use it in GitHub Desktop.
# custom Authorization
from tastypie.authorization import Authorization
class SimpleReaderAuthorization(Authorization):
def read_list(self, object_list, bundle):
return object_list.filter(email=bundle.request.user.email)
# resource
class MyUserResource(ModelResource):
class Meta:
queryset = ReaderUser.objects.all()
resource_name = 'me'
list_allowed_methods = []
detail_allowed_methods = ['get']
authorization = SimpleReaderAuthorization()
authentication = SessionAuthentication()
excludes = ('password', 'id', 'is_active', 'is_admin', 'last_login')
def prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_de tail"),
]
#urls
myuser_resource = MyUserResource()
url(r'^api/', include(myuser_resource.urls)),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment