Django Selection Options

I am creating an application in which there is a file name field, a download field and a selection. Let's say I have something like this for selection

<select name="menu"> <option value="0" selected> select imp </option> <option value="1"> imp 1 </option> <option value="2"> imp 2 </option> <option value="3"> imp 3 </option> <option value="4"> imp 4 </option> </select> <input type="submit" value="Upload" /> 

I have a file upload working with this class

 class UploadFileForm(forms.Form): title = forms.CharField(max_length=50) file = forms.FileField(widget=forms.FileInput()) 

What should a class look like with an element added to it? Or how can I use the file upload form and get the value from the selection and perform an action based on this value?

+7
python django drop-down-menu forms combobox
source share
1 answer

You need to use ChoiceField :

 IMP_CHOICES = ( ('1', 'imp 1'), ('2', 'imp 2'), ('3', 'imp 3'), ('4', 'imp 4'), ) class UploadFileForm(forms.Form): title = forms.CharField(max_length=50) file = forms.FileField(widget=forms.FileInput()) imp = forms.ChoiceField(choices=IMP_CHOICES) 
+12
source share

All Articles