Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

367
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda