python - multiple file upload django -
i know how mutiple file upload in djnago. use:
<form enctype="multipart/form-data" action="" method="post"> {% csrf_token %} <p>press control upload more image @ same time</p> <input type="file" name="myfiles" multiple> <input type="submit" name="upload" value="upload"> </form> but want single file upload, permit user click in a"+" button , automatic create new file upload, permit user upload mutiple files. attach file in hotmail.
you're looking formset - set of multiple forms, , javascript populate new forms.
https://docs.djangoproject.com/en/dev/topics/forms/formsets/
here references js code dynamically build html new forms:
dynamically adding form django formset ajax
setting formsets easy (it's documented everywhere), might want js part:
i use different method dynamically add forms. set hidden div formset.empty_form comes replaceable __prefix__es in attributes:
var form_count = {{ formset.total_form_count }}; $('#add_form').click(function() { var form = $("#empty_form").html().replace(/__prefix__/g, form_count); $('#forms').append(form); form_count++; $('#id_form-total_forms').val(form_count); }); <div id="empty_form" style="display:none;"> {{ formset.empty_form.as_p }} </div> <div id="add_form">add form</div> <form id="forms"> {{ formset.management_form }} {% form in formset %} {{ form.as_p }} {% endfor %} </form>
Comments
Post a Comment