简体   繁体   中英

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???

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

should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM