diff options
| author | Chris Beaven <smileychris@gmail.com> | 2011-05-10 00:28:05 +0000 |
|---|---|---|
| committer | Chris Beaven <smileychris@gmail.com> | 2011-05-10 00:28:05 +0000 |
| commit | 7fd113e6184c1602e4ad6d6d7a92c78a158e78ff (patch) | |
| tree | 9a5d54658c4f1156c18b54f85104c463954c09bb /docs | |
| parent | 4cb2b53c222a8b02941d7bd32f012e62c1acd94f (diff) | |
[1.3.X] Fixes #15963 -- Misleading FileField.save documentation. Thanks for the report and patch, ejucovy.
Backport of r16207 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16208 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/fields.txt | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index 66bd04791b..2fb5d494b1 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -607,9 +607,26 @@ instances on your model, the ``save()`` method is used to persist that file data. Takes two required arguments: ``name`` which is the name of the file, and -``content`` which is a file-like object containing the file's contents. The -optional ``save`` argument controls whether or not the instance is saved after -the file has been altered. Defaults to ``True``. +``content`` which is an object containing the file's contents. The +optional ``save`` argument controls whether or not the instance is +saved after the file has been altered. Defaults to ``True``. + +Note that the ``content`` argument should be an instance of +:class:`django.core.files.File`, not Python's built-in file object. +You can construct a :class:`~django.core.files.File` from an existing +Python file object like this:: + + from django.core.files import File + # Open an existing file using Python's built-in open() + f = open('/tmp/hello.world') + myfile = File(f) + +Or you can construct one from a Python string like this:: + + from django.core.files.base import ContentFile + myfile = ContentFile("hello world") + +For more information, see :doc:`/topics/files`. .. method:: FieldFile.delete(save=True) |
