form.py
class Upload_Form(ModelForm):
class Meta:
model = Upload
class Upload_Item_Form(ModelForm):
class Meta:
model = Upload_Item
exclude = ('list',)
models.py
class Upload(models.Model):
title = models.CharField(max_length=10)
contents=models.TextField()
def __unicode__(self):
return self.title+self.contents
class Upload_Item(models.Model):
model_pic = models.FileField(upload_to = 'pic_folder/')
tag = models.CharField(max_length=50)
list=models.ForeignKey(Upload)
def __unicode__(self):
return self.model_pic+self.tag + " (" + str(self.list) + ")"
html的
<form action="" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="section">
{{ Upload_list_form.title }}
{{ Upload_list_form.contents }}
</div>
<input name="filesToUpload[]" id="filesToUpload" type="file" multiple="" />
<h2>Image</h2>
<input type="hidden" id="inputForm"/>
<input type="submit" value=" Submit " />
{{ upload_image_item_formset.management_form }}
{% for form in upload_image_item_formset.forms %}
{% endfor %}
</form>
{% endblock %}
我想使用多个输入,例如 name =“filesToUpload []”id =“filesToUpload”type =“file”multiple =“”
添加表单和更新表单以编写数据库 并使用本地资源显示图像,例如在javascript中使用FileReder。
希望它有所帮助。 感谢