From 4da29717fd46234d5b44705646f629800c80982a Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 22 Apr 2011 12:03:50 +0000 Subject: [PATCH] Fixed #15673 -- Allow limit_choices_to to use a tuple for __in filters. Thanks, EnTeQuAk. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16078 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/widgets.py | 2 +- tests/regressiontests/admin_widgets/tests.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index f210d4ec79..957f94fd00 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -99,7 +99,7 @@ def url_params_from_lookup_dict(lookups): if lookups and hasattr(lookups, 'items'): items = [] for k, v in lookups.items(): - if isinstance(v, list): + if isinstance(v, (tuple, list)): v = u','.join([str(x) for x in v]) elif isinstance(v, bool): # See django.db.fields.BooleanField.get_prep_lookup diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py index 7ad74a3785..9fde201366 100644 --- a/tests/regressiontests/admin_widgets/tests.py +++ b/tests/regressiontests/admin_widgets/tests.py @@ -8,7 +8,8 @@ from django.contrib import admin from django.contrib.admin import widgets from django.contrib.admin.widgets import (FilteredSelectMultiple, AdminSplitDateTime, AdminFileWidget, ForeignKeyRawIdWidget, AdminRadioSelect, - RelatedFieldWidgetWrapper, ManyToManyRawIdWidget) + RelatedFieldWidgetWrapper, ManyToManyRawIdWidget, + url_params_from_lookup_dict) from django.core.files.storage import default_storage from django.core.files.uploadedfile import SimpleUploadedFile from django.db.models import DateField @@ -180,6 +181,12 @@ class AdminForeignKeyRawIdWidget(DjangoTestCase): self.assertContains(response, 'Select a valid choice. That choice is not one of the available choices.') + def test_url_params_from_lookup_dict_any_iterable(self): + lookup1 = url_params_from_lookup_dict({'color__in': ('red', 'blue')}) + lookup2 = url_params_from_lookup_dict({'color__in': ['red', 'blue']}) + self.assertEqual(lookup1, {'color__in': 'red,blue'}) + self.assertEqual(lookup1, lookup2) + class FilteredSelectMultipleWidgetTest(TestCase): def test_render(self):