Skip to content

Commit

Permalink
Fixed #15673 -- Allow limit_choices_to to use a tuple for __in filter…
Browse files Browse the repository at this point in the history
…s. Thanks, EnTeQuAk.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16078 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jezdez committed Apr 22, 2011
1 parent 7478aeb commit 4da2971
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django/contrib/admin/widgets.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def url_params_from_lookup_dict(lookups):
if lookups and hasattr(lookups, 'items'): if lookups and hasattr(lookups, 'items'):
items = [] items = []
for k, v in lookups.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]) v = u','.join([str(x) for x in v])
elif isinstance(v, bool): elif isinstance(v, bool):
# See django.db.fields.BooleanField.get_prep_lookup # See django.db.fields.BooleanField.get_prep_lookup
Expand Down
9 changes: 8 additions & 1 deletion tests/regressiontests/admin_widgets/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from django.contrib.admin import widgets from django.contrib.admin import widgets
from django.contrib.admin.widgets import (FilteredSelectMultiple, from django.contrib.admin.widgets import (FilteredSelectMultiple,
AdminSplitDateTime, AdminFileWidget, ForeignKeyRawIdWidget, AdminRadioSelect, 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.storage import default_storage
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.db.models import DateField from django.db.models import DateField
Expand Down Expand Up @@ -180,6 +181,12 @@ def test_invalid_target_id(self):
self.assertContains(response, self.assertContains(response,
'Select a valid choice. That choice is not one of the available choices.') '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): class FilteredSelectMultipleWidgetTest(TestCase):
def test_render(self): def test_render(self):
Expand Down

0 comments on commit 4da2971

Please sign in to comment.