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

newforms-admin: Moved list_select_related from AdminOptions to ModelAdmin.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4335 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-01-16 00:51:22 +00:00
parent c9e4b37290
commit 93e024365d
4 changed files with 7 additions and 6 deletions

View File

@ -36,6 +36,7 @@ class ModelAdmin(object):
list_display = ('__str__',)
list_display_links = ()
list_filter = ()
list_select_related = False
search_fields = ()
date_hierarchy = None
save_as = False
@ -275,7 +276,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.date_hierarchy, self.search_fields, self.list_select_related)
except IncorrectLookupParameters:
# Wacky lookup parameters were given, so redirect to the main
# changelist page, without parameters, and pass an 'invalid=1'

View File

@ -292,7 +292,7 @@ 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):
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related):
self.model = model
self.opts = model._meta
self.lookup_opts = self.opts
@ -302,6 +302,7 @@ class ChangeList(object):
self.list_filter = list_filter
self.date_hierarchy = date_hierarchy
self.search_fields = search_fields
self.list_select_related = list_select_related
# Get search parameters from the query string.
try:
@ -432,7 +433,7 @@ class ChangeList(object):
# Use select_related() if one of the list_display options is a field
# with a relationship.
if self.lookup_opts.admin.list_select_related:
if self.list_select_related:
qs = qs.select_related()
else:
for field_name in self.list_display:

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')]))
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')]))
value.contribute_to_class(cls, name)
elif hasattr(value, 'contribute_to_class'):
value.contribute_to_class(cls, name)

View File

@ -201,12 +201,11 @@ class Options(object):
class AdminOptions(object):
def __init__(self, fields=None, js=None,
ordering=None,
save_on_top=False, list_select_related=False, manager=None, list_per_page=100):
save_on_top=False, manager=None, list_per_page=100):
self.fields = fields
self.js = js or []
self.ordering = ordering
self.save_on_top = save_on_top
self.list_select_related = list_select_related
self.list_per_page = list_per_page
self.manager = manager or Manager()