I have a form which has to do multiple file uploads at once, through Django ModelForm.
The scenario is like, I have a form in which different categories of documents has to be attached. For example, there maybe Medical records, Physician referrals, Diagnostic reports, etc. Each of these categories are stored in the DB. I have to upload all these documents according to their respective categories, through a single form submission.
Here are my Django models.
class Patient(models.Model):
first_name = models.CharField(_("First Name"), max_length=30)
last_name = models.CharField(_("Last Name"), max_length=30)
email = models.EmailField(max_length=255)
class DocumentType(models.Model):
"""
Type of document to be attached alongside a Patient.
"""
name = models.CharField(max_length=255)
class DocumentFile(BaseModel):
"""
Documents to be attached alongside each document type within a
Patient Case. Multiple documents to be attached.
"""
type = models.ForeignKey(DocumentType)
attachment = models.FileField(upload_to=get_new_documents_path, blank=True)
patient = models.ForeignKey(Patient, related_name="get_applicable_documents")
Please tell me which is the best method to process the form submission. Any help would be much appreciated.