django-nonrel / djangotoolbox

Django tools for building nonrel backends
BSD 3-Clause "New" or "Revised" License
200 stars 125 forks source link

Open Admin User change_list_view got error 'This query is not supported by the database' #46

Closed ace-han closed 10 years ago

ace-han commented 10 years ago

All the library I installed comes from pip install django-mongodb-engine only

And I follow the tutorial, still got below error once login admin site, and click User link

I've already got INSTALLED_APP including djangotoolbox and django_mongodb_engine as the troubleshooting suggested

[10/Dec/2013 18:20:04] "GET /admin/ HTTP/1.1" 200 3249
Internal Server Error: /admin/auth/user/
Traceback (most recent call last):
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\core\handlers\ba
se.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\contrib\admin\op
tions.py", line 372, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\utils\decorators
.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\views\decorators
\cache.py", line 89, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\contrib\admin\si
tes.py", line 202, in inner
    return view(request, *args, **kwargs)
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\utils\decorators
.py", line 25, in _wrapper
    return bound_func(*args, **kwargs)
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\utils\decorators
.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\utils\decorators
.py", line 21, in bound_func
    return func(self, *args2, **kwargs2)
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\contrib\admin\op
tions.py", line 1285, in changelist_view
    'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},

  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\db\models\query.
py", line 106, in __len__
    self._result_cache = list(self.iterator())
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\django\db\models\query.
py", line 317, in iterator
    for row in compiler.results_iter():
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\djangotoolbox\db\baseco
mpiler.py", line 375, in results_iter
    results = self.build_query(fields).fetch(
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\djangotoolbox\db\baseco
mpiler.py", line 477, in build_query
    self.check_query()
  File "D:\Dev\python\Envs\vizpropspy2\lib\site-packages\djangotoolbox\db\baseco
mpiler.py", line 455, in check_query
    raise DatabaseError("This query is not supported by the database.")
nitzanw commented 10 years ago

did you find a solution for this?

aburgel commented 10 years ago

This is probably caused by a join. Are you using the builtin user model?

aburgel commented 10 years ago

To provide some more information on this. The builtin user model uses a many-to-many field for permissions. This field requires a join, so it obviously won't work with MongoDB. Take a look at djangotoolbox/admin.py, that shows how to setup the User admin to stop the join from happening.

If you need to use permissions, then you should look at django-nonrel/django-permission-backend-nonrel.

nitzanw commented 10 years ago

hi aburgel, I don't understand why looking at the djangotoolbox/admin.py could show me how to setup the User admin... anyways, my problem is not really setting up the admin user, but setting up all other users. All of my users inherit from django's auth.user and thus I have this join issue, and each time I enter the "Users" link in the admin ui I get a : "DatabaseError at /admin/auth/user/ This query is not supported by the database." and I thought it's related to your issue. tnx, Nitzan

aburgel commented 10 years ago

As I explained, the builtin User model uses a many-to-many field for permissions. This is not supported by mongodb, so you must disable it. djangotoolbox/admin.py will show you how to disable it.

nitzanw commented 10 years ago

I understand what you said about the many-to-many field, and that the builtin User model uses it, I just didn't understand the reference to djangotoolbox/admin.py: should I edit it? should I run it? should it just be there, and it'll take care of everything?

aburgel commented 10 years ago

Is djangotoolbox in your INSTALLED_APPS list? If so, then it should already be working. What djangotoolbox/admin.py does is customize the User admin screen to not show the many-to-many field, so you won't trigger the join.

nitzanw commented 10 years ago

Yes, it's in my INSTALLED_APPS, just under django_mongodb_engine.. If I open my project's manage.py shell and do "import djangotoolbox " it doesn't even throw an error. I wonder what wrong then...

ace-han commented 10 years ago

Hi, Aburgel

Let's put away the auth staff first, focus on djangotoolbox's issue first.

Since djangotoolbox/admin.py has already unregistered the built-in user model and done below

admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.register(User, CustomUserAdmin)

There should have nothing extra we needed to do already. However, as I first opened this issue, I've already added djangotoolbox in INSTALLED_APPS, still found no luck

Could you show steps for a smooth Get Started guildline for us to followup, thx. already_added_djangotoolbox

kmad1729 commented 10 years ago

Hi All,

I am also facing the same issue:

screen shot 2013-12-16 at 6 30 35 pm

needless to say, i added djangotoolbox to the INSTALLED_APPS

aburgel commented 10 years ago

I just pushed up a fix to the master branch. Give it a try. I tested it with django 1.6, but it should also work with django 1.5. I'm going to close the issue but please reopen if you still have issues.

nitzanw commented 10 years ago

Can you submit the order of your INSTALLED_APPS?

aburgel commented 10 years ago

djangotoolbox needs to go after django.contrib.auth. I think thats all that matters.

nitzanw commented 10 years ago

Ok, Sorry for the mix-up, this is what I wanted to submit: I'm able to enter the "admin/auth/user/add/", what I couldn't before, but after submitting the new user I get the following screen: nonrel-user_render I'm not sure if it's related to this issue, or I should open a new one, or maybe it's a django-non-rel issue altogether. When returning to the "admin/auth/user/add/" I can see the users were created.

aburgel commented 10 years ago

I think this is a different issue. If you need help on this, please post in the forums.