1👍
✅
from the docs (here)
you can use the select
widget and specify choices. In your case
color = forms.CharField(max_length=20, widget=forms.Select(choices=COLORS))
However, since you’ve already defined color
with choices
you in fact do not need to do anything (other than set the meta of BrowseForm
to Thing
) to get this to work. It will default to the behavior you want.
1👍
You could use a Model form
from django.forms import ModelForm
class BrowseForm(ModelForm):
class Meta:
model = Thing
It would then pull in your choices automatically.
Source:stackexchange.com