Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
Upload multiple files at once, with different sets of categories - Django forms

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.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I've been working on a Django project and also have to submit forms that contain file uploads. I don't know how exactly you interact with your users, but I can explain my case and hope it helps and has some relatability to yours.

In my case I use the FormData interface ("multipart") to submit my forms via the Web, performing POSTs to the server. My forms sometimes contain only simple fields, and other times may contain various File Uploads. You can use the FormData interface and append multiple fields to an object, and then send it to your Django Server via POSTing. In my case, I'm also using it with JQuery AJAX asynchronously, though that's not a requirement.

You can find the basic idea for this at W3Schools, and you can try some javascript examples here. Also, if you have any asynchronous constraints, AJAX, there's a good starting point here on Stack Overflow.

Good luck

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda