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

Sign up to request clarification or add additional context in comments.

1 Comment

That's the answer I needed! Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.