From a52cc033749d288aa117f480959e43e7c8b8f031 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 20 Feb 2007 03:05:09 +0000 Subject: Fixed #3490 -- Fixed issue with newforms ChoiceField and generators as choices. Thanksfor the patch, Chris.Wesseling@cwi.nl git-svn-id: http://code.djangoproject.com/svn/django/trunk@4549 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/tests.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/regressiontests/forms') diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index c4502b2202..4183002809 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -318,6 +318,7 @@ The value is compared to its str(): The 'choices' argument can be any iterable: +>>> from itertools import chain >>> def get_choices(): ... for i in range(5): ... yield (i, i) @@ -329,6 +330,17 @@ The 'choices' argument can be any iterable: +>>> things = ({'id': 1, 'name': 'And Boom'}, {'id': 2, 'name': 'One More Thing!'}) +>>> class SomeForm(Form): +... somechoice = ChoiceField(choices=chain((('', '-'*9),), [(thing['id'], thing['name']) for thing in things])) +>>> f = SomeForm() +>>> f.as_table() +u'' +>>> f.as_table() +u'' +>>> f = SomeForm({'somechoice': 2}) +>>> f.as_table() +u'' You can also pass 'choices' to the constructor: >>> w = Select(choices=[(1, 1), (2, 2), (3, 3)]) -- cgit v1.3