我可以使用javascript添加和修改Django表单吗?

2024-03-28 21:51:19 发布

您现在位置:Python中文网/ 问答频道 /正文

你知道吗表格.py你知道吗

class Upload_Form(ModelForm):
    class Meta:
        model = Upload

class Upload_Item_Form(ModelForm):
    class Meta:
        model = Upload_Item
        exclude = ('list',)

你知道吗型号.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一样。你知道吗

希望有帮助。 谢谢


Tags: selfforminputmodeltitlemodelstypecontents