I'm making an app that has a file name field, an upload file field and a select. Lets say I have something like this for the select
<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 the file upload working with this class
class UploadFileForm(forms.Form):
title = forms.CharField(max_length=50)
file = forms.FileField(widget=forms.FileInput())
How should the class look with the select added to it? Or how can I use the file upload form and get the value from the select, and based on that value do an action?
You need to use a 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With