0

in my django project i create my models like thisone:

class v_candidatura(models.Model):
    c_data = models.DateTimeField(auto_now=True, verbose_name="Upload")
    c_tit = models.CharField(max_length=5, verbose_name="Titolo")
    c_sur = models.CharField(max_length=100, verbose_name="Cognome")
    c_name = models.CharField(max_length=100, verbose_name="Nome")
    c_dob = models.CharField(max_length=50, verbose_name="Data di nascita")
    c_res = models.CharField(max_length=200, verbose_name="Residenza")
    c_email = models.CharField(max_length=100, verbose_name="Email")
    c_mansione = models.CharField(max_length=50, verbose_name="Mansione")
    c_en = models.CharField(max_length=50, verbose_name="Conoscenza EN")
    c_de = models.CharField(max_length=50, verbose_name="Conoscenza DE")
    c_pres = models.TextField(null=True, blank=True, verbose_name="Presentazione")
    c_cv = models.FileField(upload_to='villagemma/static/docs', max_length=254, validators=[FileExtensionValidator(['pdf']),validate_fsize], verbose_name="CV")

    class Meta:
        verbose_name = "Candidature"
        verbose_name_plural = "Candidature"

    def __str__(self):
        return str(self.c_sur)

whell i have a long html for with a file field for upload file:

...    
<input type="file" class="form-control input_login custom-file-input" id="inputCv" name="inputCv">
...

in my view.py i would save data and file in my table so i do:

if request.method == "POST":
    #try to save data into db
    a = v_candidatura(c_tit = request.POST['inputTitolo'],
     c_sur = request.POST['inputCognome'],
     c_name = request.POST['inputNome'],
     c_dob = request.POST['inputDtNascita'],
     c_res = request.POST['inputComune'],
     c_email = request.POST['inputEmail'],
     c_mansione = request.POST['inputMansione'],
     c_en = request.POST['inputEN'],
     c_de = request.POST['inputDE'],
     c_pres = request.POST['inputPresentazione'],
     c_cv = request.POST['inputCv']
     )
    a.save()

but i get multidictate error on inputCv value. How can i save my form data into table and also file uploaded from form?

So many thanks in advance

Manuel Santi
  • 1,106
  • 17
  • 46

1 Answers1

0

you should change

c_cv = request.POST['inputCv']

to

c_cv = request.FILES['inputCv']

https://docs.djangoproject.com/en/3.0/ref/request-response/#django.http.HttpRequest.FILES

Vit Amin
  • 574
  • 5
  • 20