Ticket #1653: forms.txt.diff

File forms.txt.diff, 1.8 KB (added by asmodai@…, 12 years ago)

Patch to document FileField and ImageField's use in forms a bit

  • docs/forms.txt

    581581    the executable specified in the ``JING_PATH`` setting (see the settings_
    582582    document for more details).
     584FileField, ImageField and forms
     587Where most, if not all, model fields only require a simple addition in the
     588form of ``{{ form.fieldname }}`` to a template, the situation is a bit
     589different for the FileField and ImageField fields.
     591Say that in the model definition there is a declaration for::
     593    file = model.FileField('/path/to/upload/location')
     595Normally this would be used in a template form like the following::
     597    <p><label for="file">File:</label> {{ form.file }}</p>
     599The first thing that is noticeable when the page is opened in a browser is
     600that there is no typical text field with a browse button, as would be
     603To get this behaviour a little change to the template is needed to get the
     606    <p><label for="file">File:</label> {{ form.file }}{{ form.file_file }}</p>
     608If you would reload the page it should now show a file upload text field
     609complete with a browse button.
     611Also make sure to use ``form.file_file`` with validation and not
     614In the view make sure that the ``update(request.FILES)`` method is called
     615after the object has been created with the ``request.POST.copy()`` call, as
     618    new_data = request.POST.copy()
     619    new_data.update(request.FILES)
    584621.. _`generic views`: http://www.djangoproject.com/documentation/generic_views/
    585622.. _`models API`: http://www.djangoproject.com/documentation/model_api/
    586623.. _settings: http://www.djangoproject.com/documentation/settings/
Back to Top