I'm trying to create a "cool" image uploading interface in django admin panel. The problem is that I'm using inline interface for uploading image instances, but I'm using jQuery Ajax form to upload images, so there were another form I need to create for uploading. And now django view function can't receive request.FILES from this form, because I've created it without using django.forms and can't specify in view function which form needs to be used. So I can't override standard view function for inline interfaces and can't recreate this form using django.forms. So this code doesn't seem to work:
My form:
<form id="uploadForm" enctype="multipart/form-data" method="post" action="upload_picture/">
<input type="file" name="file" />
<input type="submit" value="Upload" />
</form>
My view function:
def upload_picture(request):
if request.method == 'POST':
save_original(request.FILES['file'])
return HttpResponseRedirect('admin/edit_inline/picture_editor.html')
Maybe I should make it completely different way?
request.FILES should work fine with that handmade form. Django doesn't do anything different with the field except adding the id="id_file". I'm fairly certain that your not having an id wouldn't interfere with the transference into request.FILES.
In [5]: from django import forms
In [6]: class GenericFileForm(forms.Form):
...: file = forms.FileField()
...:
In [7]: g = GenericFileForm()
In [8]: print g
<tr><th><label for="id_file">File:</label></th><td><input type="file" name="file" id="id_file" /></td></tr>
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