1

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?

1 Answer 1

2

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

1
  • That's the answer I needed! Thanks!
    – John Doe
    Dec 27, 2013 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.