I need user to upload an excel file via the form provided and i need to process that uploaded excel file to save the data in my model.
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
I have simple form to upload the file.
<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>
Can someone help me with the code to parse a excel file using POST to this model.
I tried using many different methods but couldn't succeed in it.