views:

42

answers:

1

ok so i`m makeing an app that has a file name field upload file field and a combobox, lets say I have smth like this for the combobox

<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 I made 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 combobox added to it ? or how can I use the file upload form and get the value from combobox and based on that value to do an action ?

regards void.

+1  A: 

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)
ars
ahh so django had a choice field after all :) Thx a lot m8.Regards void,
void