cleaned_data doesn't get populated until is_valid() is called on the
form, the save method will be trying to access the cleaned_data fields
so that is likely what's causing the problems.

- Andrew Ingram

On May 22, 9:11 pm, jabbercat <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I want to upload files with a Form generated by form_for_model(). The
> form is ok, but I can't upload files, because I get different errors.
>
> I get an error, that FileForm has no attribute cleaned_data. Knows
> somebody the problem?
>
> Here my code:
>
> The template:
>
> <html>
> <head>
>         <title>Add a file</title>
> </head>
>         <form enctype="multipart/form-data" action="." method="POST">
>                 <table>
>                         {{ form.as_table }}
>                 <table>
>                 <input type = "hidden" name = "paragraph" value =
> "{{ paragraph_id  }}">
>                 <input type = "Submit" value = "Hinzufügen">
>         </form>
> </html>
>
> The view:
>
> def addFile(request, paragraph_id):
>         if request.method == 'POST':
>                 FileForm = form_for_model(File)
>
>                 form = FileForm()
>
>                 form.id = request.POST['paragraph']
>                 form.name = request.POST['name']
>                 form.url = request.FILES['url']
>
>                 try:
>                         form.save()
>                 except ValueError, error:
>                         #raise ValueError
>                         return render_to_response('error.html', {'message' :
> error.message})
>
>                 return HttpResponseRedirect('/contracts/')
>
>         else:
>                 FileForm = form_for_model(File, fields=('name','url'))
>                 form = FileForm()
>                 return render_to_response('addFile.html', {'form': form,
> 'paragraph_id': paragraph_id})
>
> The Model:
>
> class File(models.Model):
>         paragraph = models.ForeignKey(Paragraph)
>         name = models.CharField(max_length=255)
>         url = models.FileField(upload_to='tmp/%Y/%m/%d')
>
>         def __str__(self):
>                 return self.name
>
>         class Admin:
>                 pass
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to