'The simple django model for selectbox

Django model with models.Choices

class Special(models.Choices):
    SPECIAL = (("welcome","My Welcome!"),
    ("privacy","my Privacy list"),
     ("happy","How happy you are"),
     ('',"-------------"))

and I have this code in form class

key_selector = forms.fields.ChoiceField(
    choices = Special.SPECIAL
    required=False,
    widget=forms.widgets.Select
)

This error comes here

TypeError: 'Special' object is not iterable

How can I make the selectbox with django???



Solution 1:[1]

key_selector = forms.fields.ChoiceField(
    choices = Special.SPECIAL.choices
    required=False,
    widget=forms.widgets.Select
)

should work

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kjaw