Added 'manager' option to Admin declaration; this controls which Manager to use for the admin queryset (defaults to the standard manager).
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2395 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
863bd3d36a
commit
3ddc1b51f5
|
@ -486,7 +486,7 @@ class ChangeList(object):
|
|||
self.model = model
|
||||
self.opts = model._meta
|
||||
self.lookup_opts = self.opts
|
||||
self.manager = model._default_manager
|
||||
self.manager = self.opts.admin.manager
|
||||
|
||||
# Get search parameters from the query string.
|
||||
try:
|
||||
|
@ -551,7 +551,7 @@ class ChangeList(object):
|
|||
if isinstance(self.query_set._filters, models.Q) and not self.query_set._filters.kwargs:
|
||||
full_result_count = result_count
|
||||
else:
|
||||
full_result_count = self.model._default_manager.count()
|
||||
full_result_count = self.manager.count()
|
||||
|
||||
can_show_all = result_count <= MAX_SHOW_ALL_ALLOWED
|
||||
multi_page = result_count > DEFAULT_RESULTS_PER_PAGE
|
||||
|
@ -603,7 +603,7 @@ class ChangeList(object):
|
|||
return order_field, order_type
|
||||
|
||||
def get_query_set(self):
|
||||
qs = self.model._default_manager.get_query_set()
|
||||
qs = self.manager.get_query_set()
|
||||
lookup_params = self.params.copy() # a dictionary of the query string
|
||||
for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR):
|
||||
if lookup_params.has_key(i):
|
||||
|
|
|
@ -3,6 +3,7 @@ from django.db.models.fields.related import ManyToMany
|
|||
from django.db.models.fields import AutoField, FieldDoesNotExist
|
||||
from django.db.models.loading import get_models
|
||||
from django.db.models.query import orderlist2sql
|
||||
from django.db.models import Manager
|
||||
from bisect import bisect
|
||||
import re
|
||||
|
||||
|
@ -194,7 +195,7 @@ class Options:
|
|||
class AdminOptions:
|
||||
def __init__(self, fields=None, js=None, list_display=None, list_filter=None,
|
||||
date_hierarchy=None, save_as=False, ordering=None, search_fields=None,
|
||||
save_on_top=False, list_select_related=False):
|
||||
save_on_top=False, list_select_related=False, manager=None):
|
||||
self.fields = fields
|
||||
self.js = js or []
|
||||
self.list_display = list_display or ['__str__']
|
||||
|
@ -204,6 +205,7 @@ class AdminOptions:
|
|||
self.search_fields = search_fields or []
|
||||
self.save_on_top = save_on_top
|
||||
self.list_select_related = list_select_related
|
||||
self.manager = manager or Manager()
|
||||
|
||||
def get_field_sets(self, opts):
|
||||
"Returns a list of AdminFieldSet objects for this AdminOptions object."
|
||||
|
@ -220,6 +222,9 @@ class AdminOptions:
|
|||
|
||||
def contribute_to_class(self, cls, name):
|
||||
cls._meta.admin = self
|
||||
|
||||
# Register the admin manager with the class as Model._admin_manager
|
||||
self.manager.contribute_to_class(cls, '_admin_manager')
|
||||
|
||||
class AdminFieldSet(object):
|
||||
def __init__(self, name, classes, field_locator_func, line_specs):
|
||||
|
|
Loading…
Reference in New Issue