“Disabled” option for choiceField - Django

前端 未结 7 1104
别跟我提以往
别跟我提以往 2020-12-24 14:02

I having trouble with a simple question : How to have some \"disabled\" field in a dropdown menu generated via a modelForm and choiceFied in the django Framework ?

7条回答
  •  失恋的感觉
    2020-12-24 14:41

    It seems django 1.1 will allow "optgroup": Django documentation

    class MyForm(forms.Form):
        some_field = forms.ChoiceField(choices=[
            ('Audio', (
                    ('vinyl', 'Vinyl'),
                    ('cd', 'CD'),
                )
            ),
            ('Video', (
                    ('vhs', 'VHS Tape'),
                    ('dvd', 'DVD'),
                )
            ),
            ('unknown', 'Unknown'),
        ])
    

    This imho is a must have.

提交回复
热议问题