﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23055	Filters don't use ModelAdmin get_queryset()	Ramiro Morales	nobody	"If one is using a ModelAdmin with a custom `get_queryset()` method e.g as described in https://docs.djangoproject.com/en/1.7/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface to handle routing of models hosted in a multi-DB setup, displaying the change list works as expected.

But when usage of the `list_filter` feature is added, a DB error is generated reporting that no table object for the model a hand is found in the default Django DB.

This is because the filter machinery doesn't use the custom ModelAdmin-dictated !QuerySet but the model's default manager `all()` method:

(https://github.com/django/django/blob/011abb7d96c75f6154c15a8a0f997d8c27698679/django/contrib/admin/filters.py#L364)

{{{
    queryset = parent_model._default_manager.all()
}}}

Replacing it with:

{{{
diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py
index d5f31ab..d04d5cc 100644
--- a/django/contrib/admin/filters.py
+++ b/django/contrib/admin/filters.py
@@ -361,7 +361,7 @@ class AllValuesFieldListFilter(FieldListFilter):
         self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull,
                                                  None)
         parent_model, reverse_path = reverse_field_path(model, field_path)
-        queryset = parent_model._default_manager.all()
+        queryset = model_admin.get_queryset(request)
         # optional feature: limit choices base on existing relationships
         # queryset = queryset.complex_filter(
         #    {'%s__isnull' % reverse_path: False})
}}}

solves the problem."	Bug	new	contrib.admin	dev	Normal		admin filters list_filter multi-db get_queryset modeladmin		Unreviewed	0	0	0	0	0	0
