Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DjangoAuthorization does not work! #89

Open
nim4n opened this issue Feb 26, 2015 · 2 comments
Open

DjangoAuthorization does not work! #89

nim4n opened this issue Feb 26, 2015 · 2 comments

Comments

@nim4n
Copy link

nim4n commented Feb 26, 2015

I have some problem in using DjangoAuthorization , when I use this in my resource I get this error:

{"error_message": "'QuerySet' object has no attribute 'model'", "traceback": "Traceback (most recent call last):\n\n File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 201, in wrapper\n response =
callback(request, _args, *_kwargs)\n\n File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 432, in dispatch_list\n return self.dispatch('list', request, *_kwargs)\n\n File "/usr/local/lib/python2.7/dist-
packages/tastypie_mongoengine/resources.py", line 374, in dispatch\n return super(MongoEngineResource, self).dispatch(request_type, request, *_kwargs)\n\n File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line
464, in dispatch\n response = method(request, *_kwargs)\n\n File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 1286, in get_list\n objects = self.obj_get_list(bundle=base_bundle,
*_self.remove_api_resource_names(kwargs))\n\n File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 2068, in obj_get_list\n return self.authorized_read_list(objects, bundle)\n\n File
"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 583, in authorized_read_list\n auth_result = self._meta.authorization.read_list(object_list, bundle)\n\n File "/usr/local/lib/python2.7/dist-
packages/tastypie/authorization.py", line 152, in read_list\n klass = self.base_checks(bundle.request, object_list.model)\n\nAttributeError: 'QuerySet' object has no attribute 'model'\n"}

but without using this It works fine, am I missed some thing? my resource is:
'''
class MainUserResource(resources.MongoEngineResource):
enduser = fields.ToOneField('interface.api.EndUserResource', 'enduser', full=False, null=True, blank=True)

    class Meta:
        queryset = User.objects.all()
        allowed_methods = ['get', 'post', 'put', 'delete']
        resource_name = 'main_user'
        fields = ['username', 'first_name', 'last_name', 'email']
        authorization = DjangoAuthorization()
        authentication = MultiAuthentication(BasicAuthentication(), SessionAuthentication())
        always_return_data = True
        list_allowed_methods = ['get', 'post', 'put', 'delete']
        filtering = {
            "username": ALL,
            "id": ALL,
            "enduser": ALL,
        }
@arjanvaneersel
Copy link

I had the same problem and noticed that all examples I found on the net and here use authorization = Authorization() and not DjangoAuthorization().

Considering the error I got the idea that DjangoAuthorization relies on the Django ORM, which -of course- wasn't made for MongoDB use.

So I'm affraid that the only way is to write your own authorization. More info about that is here: http://django-tastypie.readthedocs.org/en/latest/authorization.html#implementing-your-own-authorization

At least for me this worked, but perhaps someone else has a better solution, as I'm also still a beginner regarding tastypie for mongoengine.

@nim4n
Copy link
Author

nim4n commented Mar 3, 2015

yes you must write your own authorization but another problem is default django permission in mongoengin does not work properly, I found the problem and solved It, you can see It in this link:
MongoEngine/mongoengine#898

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants