Use a modal form for this which includes a file field that has required set to false.
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#topics-forms-modelforms http://docs.djangoproject.com/en/dev/ref/forms/fields/#filefield Easier to let django handle the request then figure it all out manually. On Jul 29, 4:29 pm, Salvatore Leone <salvatore.le...@isti.cnr.it> wrote: > Hello again, > > I know this is probably an already discussed question, but I can't get > out of this. I've got a form which may or may not send a file, here is > the snippet of my view function: > > if request.method == POST: > #process the form > ... > > if request.FILES: > attached_file = request.FILES['attached_file'] > attach = Attach() # my model holding the file > attach.file(attached_file) > attach.save() > > and here is my model for attachs: > > class Attach(models.Model): > attached_file = models.FileField(upload_to='file_risposte') > risposta = models.ForeignKey(Risposte) > > the problem is that *never* saves an attach. > > any idea? > > -Salvatore --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---