1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

newforms-admin: Backwards-incompatible change: Removed undocumented Admin.manager option in favor of Admin.change_list_queryset() method

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4342 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-01-17 02:13:06 +00:00
parent 08328ea847
commit 4fc14c6f7a
4 changed files with 10 additions and 11 deletions

View File

@ -95,6 +95,9 @@ class ModelAdmin(object):
opts = self.opts
return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission())
def change_list_queryset(self, request):
return self.model._default_manager.get_query_set()
def add_view(self, request, show_delete=False, form_url='', post_url=None, post_url_continue='../%s/', object_id_override=None):
"The 'add' admin view for this model."
from django.contrib.admin.views.main import render_change_form
@ -280,7 +283,7 @@ class ModelAdmin(object):
raise PermissionDenied
try:
cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,
self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page)
self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self)
except IncorrectLookupParameters:
# Wacky lookup parameters were given, so redirect to the main
# changelist page, without parameters, and pass an 'invalid=1'

View File

@ -293,11 +293,11 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current
perms_needed.add(related.opts.verbose_name)
class ChangeList(object):
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page):
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, model_admin):
self.model = model
self.opts = model._meta
self.lookup_opts = self.opts
self.manager = self.opts.admin.manager
self.root_query_set = model_admin.change_list_queryset(request)
self.list_display = list_display
self.list_display_links = list_display_links
self.list_filter = list_filter
@ -372,7 +372,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.manager.count()
full_result_count = self.root_query_set.count()
can_show_all = result_count <= MAX_SHOW_ALL_ALLOWED
multi_page = result_count > self.list_per_page
@ -424,7 +424,7 @@ class ChangeList(object):
return order_field, order_type
def get_query_set(self):
qs = self.manager.get_query_set()
qs = self.root_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):

View File

@ -137,7 +137,7 @@ class Model(object):
# of ModelAdmin.
cls._meta.ModelAdmin = type('ModelAdmin', (value, ModelAdmin), {})
# This AdminOptions stuff is legacy and will eventually be removed.
value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_') and k not in ('list_display', 'list_display_links', 'list_filter', 'date_hierarchy', 'save_as', 'search_fields', 'list_select_related', 'list_per_page', 'ordering', 'save_on_top', 'js')]))
value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_') and k not in ('list_display', 'list_display_links', 'list_filter', 'date_hierarchy', 'save_as', 'search_fields', 'list_select_related', 'list_per_page', 'ordering', 'save_on_top', 'js', 'manager')]))
value.contribute_to_class(cls, name)
elif hasattr(value, 'contribute_to_class'):
value.contribute_to_class(cls, name)

View File

@ -4,7 +4,6 @@ from django.db.models.fields.related import ManyToManyRel
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
@ -199,9 +198,8 @@ class Options(object):
return self._field_types[field_type]
class AdminOptions(object):
def __init__(self, fields=None, manager=None):
def __init__(self, fields=None):
self.fields = fields
self.manager = manager or Manager()
def get_field_sets(self, opts):
"Returns a list of AdminFieldSet objects for this AdminOptions object."
@ -220,8 +218,6 @@ class AdminOptions(object):
def contribute_to_class(self, cls, name):
cls._meta.admin = self
# Make sure the admin manager has access to the model
self.manager.model = cls
class AdminFieldSet(object):
def __init__(self, name, classes, field_locator_func, line_specs, description):