Last active
December 23, 2015 19:39
-
-
Save jrm2k6/6683921 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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