Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

newforms-admin: Backwards-incompatible change: Removed undocumented A…

…dmin.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
  • Loading branch information...
commit 4fc14c6f7a04bb3f5b147fff6f840efb1b2f04e8 1 parent 08328ea
Adrian Holovaty authored
5  django/contrib/admin/options.py
@@ -95,6 +95,9 @@ def has_delete_permission(self, request, object_id):
95 95
         opts = self.opts
96 96
         return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission())
97 97
 
  98
+    def change_list_queryset(self, request):
  99
+        return self.model._default_manager.get_query_set()
  100
+
98 101
     def add_view(self, request, show_delete=False, form_url='', post_url=None, post_url_continue='../%s/', object_id_override=None):
99 102
         "The 'add' admin view for this model."
100 103
         from django.contrib.admin.views.main import render_change_form
@@ -280,7 +283,7 @@ def change_list_view(self, request):
280 283
             raise PermissionDenied
281 284
         try:
282 285
             cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,
283  
-                self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page)
  286
+                self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self)
284 287
         except IncorrectLookupParameters:
285 288
             # Wacky lookup parameters were given, so redirect to the main
286 289
             # changelist page, without parameters, and pass an 'invalid=1'
8  django/contrib/admin/views/main.py
@@ -293,11 +293,11 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current
293 293
                 perms_needed.add(related.opts.verbose_name)
294 294
 
295 295
 class ChangeList(object):
296  
-    def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page):
  296
+    def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, model_admin):
297 297
         self.model = model
298 298
         self.opts = model._meta
299 299
         self.lookup_opts = self.opts
300  
-        self.manager = self.opts.admin.manager
  300
+        self.root_query_set = model_admin.change_list_queryset(request)
301 301
         self.list_display = list_display
302 302
         self.list_display_links = list_display_links
303 303
         self.list_filter = list_filter
@@ -372,7 +372,7 @@ def get_results(self, request):
372 372
         if isinstance(self.query_set._filters, models.Q) and not self.query_set._filters.kwargs:
373 373
             full_result_count = result_count
374 374
         else:
375  
-            full_result_count = self.manager.count()
  375
+            full_result_count = self.root_query_set.count()
376 376
 
377 377
         can_show_all = result_count <= MAX_SHOW_ALL_ALLOWED
378 378
         multi_page = result_count > self.list_per_page
@@ -424,7 +424,7 @@ def get_ordering(self):
424 424
         return order_field, order_type
425 425
 
426 426
     def get_query_set(self):
427  
-        qs = self.manager.get_query_set()
  427
+        qs = self.root_query_set
428 428
         lookup_params = self.params.copy() # a dictionary of the query string
429 429
         for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR):
430 430
             if lookup_params.has_key(i):
2  django/db/models/base.py
@@ -137,7 +137,7 @@ def add_to_class(cls, name, value):
137 137
             # of ModelAdmin.
138 138
             cls._meta.ModelAdmin = type('ModelAdmin', (value, ModelAdmin), {})
139 139
             # This AdminOptions stuff is legacy and will eventually be removed.
140  
-            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')]))
  140
+            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')]))
141 141
             value.contribute_to_class(cls, name)
142 142
         elif hasattr(value, 'contribute_to_class'):
143 143
             value.contribute_to_class(cls, name)
6  django/db/models/options.py
@@ -4,7 +4,6 @@
4 4
 from django.db.models.fields import AutoField, FieldDoesNotExist
5 5
 from django.db.models.loading import get_models
6 6
 from django.db.models.query import orderlist2sql
7  
-from django.db.models import Manager
8 7
 from bisect import bisect
9 8
 import re
10 9
 
@@ -199,9 +198,8 @@ def has_field_type(self, field_type, follow=None):
199 198
         return self._field_types[field_type]
200 199
 
201 200
 class AdminOptions(object):
202  
-    def __init__(self, fields=None, manager=None):
  201
+    def __init__(self, fields=None):
203 202
         self.fields = fields
204  
-        self.manager = manager or Manager()
205 203
 
206 204
     def get_field_sets(self, opts):
207 205
         "Returns a list of AdminFieldSet objects for this AdminOptions object."
@@ -220,8 +218,6 @@ def get_field_sets(self, opts):
220 218
 
221 219
     def contribute_to_class(self, cls, name):
222 220
         cls._meta.admin = self
223  
-        # Make sure the admin manager has access to the model
224  
-        self.manager.model = cls
225 221
 
226 222
 class AdminFieldSet(object):
227 223
     def __init__(self, name, classes, field_locator_func, line_specs, description):

0 notes on commit 4fc14c6

Please sign in to comment.
Something went wrong with that request. Please try again.