Reputation: 145
Hey I have Django model (CharField,CharField,FileField) with fields creating a form like this:
## Form ##
- To (text input)
- Comment (text input)
- Attachment (file input)
[submit button]
Currently the file is being uploaded when I submit the form. How can I make 'upload button' so the files can be uploaded before I submit the form?
Upvotes: 1
Views: 226
Reputation: 3467
since your question was a little vague, so is this answer
You will have to upload file over ajax first, then get the pk of that uploaded file in ajax response.. Hit submit. Then again get the instance of that file using its pk.
file_instance = File.objects.get(pk=pk)
And save the
Form(initial={'file': file_instance}, data=request.POST).save()
And you might wanna take upload field out of your form to avoid double submission
Upvotes: 2