| 317 | Really, the 'choices' argument can be any iterable: |
| 318 | >>> from itertools import chain |
| 319 | >>> things = ({'id':1, 'name':'And Boom'}, {'id':2, 'name':'One More Thing!'}) |
| 320 | >>> class SomeForm(Form): |
| 321 | ... somechoice = ChoiceField(choices=chain((('', '-'*9),), ( (thing['id'], thing['name']) for thing in things ))) |
| 322 | >>> f = SomeForm() |
| 323 | >>> f.as_table() |
| 324 | u'<tr><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>' |
| 325 | >>> f.as_table() |
| 326 | u'<tr><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>' |
| 327 | |
| 328 | One More Thing: |
| 329 | >>> f = SomeForm({'somechoice': 2}) |
| 330 | >>> f.as_table() |
| 331 | u'<tr><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="">---------</option>\n<option value="1">And Boom</option>\n<option value="2" selected="selected">One More Thing!</option>\n</select></td></tr>' |
| 332 | |