【发布时间】:2018-02-12 18:08:21
【问题描述】:
我需要用户通过提供的表单上传一个 excel 文件,我需要处理上传的 excel 文件以将数据保存在我的模型中。
models.py
class Patient_Record(models.Model):
Patient_id=models.IntegerField(unique=True)
Patient_sex=models.CharField(max_length=1,choices=Gender)
Patient_name=models.CharField(max_length=20)
Patient_sugar=models.DecimalField(decimal_places=3,max_digits=6)
Patient_chlorestrol=models.DecimalField(decimal_places=3,max_digits=6)
Patient_iron=models.DecimalField(decimal_places=3,max_digits=6)
Patient_haemoglobin=models.DecimalField(decimal_places=3,max_digits=6)
def __str__(self):
return self.pat_name
我有简单的表格来上传文件。
<form method="POST" class="post-form" action="../Uploaded_file" enctype="multipart/form-data" name="myfile">{% csrf_token %}
{{ upload_form.as_p }}
<input type="submit" value="Upload" name="Upload" class="btn btn-primary">
</form>
有人可以帮助我使用 POST 解析 Excel 文件的代码到此模型。
我尝试了许多不同的方法,但都没有成功。
【问题讨论】: