Skip to content
Browse files

Fixed #1653 -- added some documentation for FileFields/ImageFields. T…

…hanks, Asmodai.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 847b1ed commit 09912cce7068c27c21a6bbc4077d76faf1a698d1 @jacobian jacobian committed
Showing with 30 additions and 0 deletions.
  1. +30 −0 docs/forms.txt
30 docs/forms.txt
@@ -404,6 +404,36 @@ Here's a simple function that might drive the above form::
errors = new_data = {}
form = forms.FormWrapper(manipulator, new_data, errors)
return render_to_response('contact_form.html', {'form': form})
+``FileField``s and ``ImageField``s
+Dealing with for ``FileField`` and ``ImageField`` is a little more
+First, you'll need to make sure that your ``<form>`` element correctly defines
+the ``enctype`` in order to upload files::
+ <form enctype="multipart/form-data" method="POST" action=".">
+Next, you'll need to treat the field in the template slightly differently.
+Given a field in the model::
+ photo = model.ImageField('/path/to/upload/location')
+You need to actually display two formfields in the template:
+ <p><label for="id_photo">Photo:</label> {{ }}{{ form.photo_file }}</p>
+The first bit (``{{ }}``) displays the currently-selected file,
+while the second (``{{ form.photo_file }}``) actually contains the file upload
+form field. Thus, at the validation layer you need to check the ``photo_file``
+Finally, in the view, make sure to call ``new_data.update(request.FILES)``::
+ new_data = request.POST.copy()
+ new_data.update(request.FILES)

0 comments on commit 09912cc

Please sign in to comment.
Something went wrong with that request. Please try again.