Using django non-rel 1.3 with MongoDB as the DB backend:
I’m trying to setting a filter on a field (CharField) of MyModel class, in the corresponding django ModelAdmin class, like this:
class MyModelAdmin(admin.ModelAdmin):
list_filter = ('myfield',)
but what i get is:
TemplateSyntaxError at /admin/myapp/mymodel
Caught DatabaseError while rendering: This query is not supported by the database.
It seems that Django MongoDB engine doesn’t support filter, but i don’t find documentation about.
EDIT:
The error comes from template file …/admin/templates/change_list.html, and the line that throws it is line 85:
{% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
My model is:
class MyModel(models.Model):
myfield=models.CharField(max_length='300')
and my admin model is:
class MyModelAdmin(admin.ModelAdmin):
list_filter = ('myfield',)
and register it with:
.
admin.site.register(MyModel, MyModelAdmin)
Debugging the code, the exception is throwed by method check_query of basecompiler.py. This method verifies that self.query.distinct or self.query.extra or self.query.having is true and then throws the exception (self.query.distinct is equal to ‘True’ in the interested query object, so the cause is this).
The error occurs because Django Admin’s list_filters use a
distinct()when trying to figure out which members belong in the list.Our (internal, hacky) solution was to patch django non_rel to make the distinct call happen in memory rather then on the DB end. This is by no means the ‘correct’ solution, and we haven’t made a point of testing it in use cases other then ours, but it’s better than nothing.
YMMV.
https://github.com/BlueDragonX/django-nonrel/commit/4025327efbe5c17c6b77e0497c2b433819c42918