From b45710875178e99852210677ac0940c50f810044 Mon Sep 17 00:00:00 2001 From: James Bennett Date: Wed, 25 Oct 2006 20:25:54 +0000 Subject: [PATCH] Fixed #1113, thanks to Jacob for spotting the deeper bug git-svn-id: http://code.djangoproject.com/svn/django/branches/0.91-bugfixes@3935 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/views/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 8ee4ef7d3f..3974f817c3 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -97,8 +97,16 @@ class ChangeList(object): self.mod, self.opts = _get_mod_opts(app_label, module_name) if not request.user.has_perm(app_label + '.' + self.opts.get_change_permission()): raise PermissionDenied - - self.lookup_mod, self.lookup_opts = self.mod, self.opts + + lookup_mod, lookup_opts = self.mod, self.opts + if self.opts.one_to_one_field: + lookup_mod = self.opts.one_to_one_field.rel.to.get_model_module() + lookup_opts = lookup_mod.Klass._meta + # If lookup_opts doesn't have admin set, give it the default meta.Admin(). + if not lookup_opts.admin: + lookup_opts.admin = meta.Admin() + + self.lookup_mod, self.lookup_opts = lookup_mod, lookup_opts def get_search_parameters(self, request): # Get search parameters from the query string. @@ -226,6 +234,8 @@ class ChangeList(object): or_queries.append(meta.Q(**{'%s__icontains' % field_name: bit})) complex_queries.append(reduce(operator.or_, or_queries)) lookup_params['complex'] = reduce(operator.and_, complex_queries) + if opts.one_to_one_field: + lookup_params.update(opts.one_to_one_field.rel.limit_choices_to) self.lookup_params = lookup_params def change_list(request, app_label, module_name):