Ticket #3442: example.py

File example.py, 676 bytes (added by tbarta@…, 17 years ago)

example usage of GroupedSelect

Line 
1import os
2os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
3
4from django.newforms import forms, fields, widgets
5from django.newforms.extras import widgets as extrawidgets
6
7choicedict = dict(
8 a='one',
9 b='two',
10 c='three',
11 yellow='banana',
12 green='pear',
13 red='apple')
14
15groups = (
16 ('letters', ('a', 'b', 'c')),
17 ('colors', ('yellow', 'red', 'green')))
18
19choices = choicedict.items()
20
21class MyForm(forms.Form):
22 linear = fields.ChoiceField(choices=choices, widget=widgets.Select)
23 grouped = fields.ChoiceField(choices=choices, widget=extrawidgets.GroupedSelect(groups=groups))
24
25f = MyForm(dict(linear='yellow', grouped='yellow'))
26print f.as_ul()
Back to Top