Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.3.X] Fixes #15963 -- Misleading FileField.save documentation. Than…

…ks 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
  • Loading branch information...
commit 7fd113e6184c1602e4ad6d6d7a92c78a158e78ff 1 parent 4cb2b53
Chris Beaven authored May 10, 2011

Showing 1 changed file with 20 additions and 3 deletions. Show diff stats Hide diff stats

  1. 23  docs/ref/models/fields.txt
23  docs/ref/models/fields.txt
@@ -607,9 +607,26 @@ instances on your model, the ``save()`` method is used to persist that file
607 607
 data.
608 608
 
609 609
 Takes two required arguments: ``name`` which is the name of the file, and
610  
-``content`` which is a file-like object containing the file's contents. The
611  
-optional ``save`` argument controls whether or not the instance is saved after
612  
-the file has been altered. Defaults to ``True``.
  610
+``content`` which is an object containing the file's contents.  The
  611
+optional ``save`` argument controls whether or not the instance is
  612
+saved after the file has been altered. Defaults to ``True``.
  613
+
  614
+Note that the ``content`` argument should be an instance of
  615
+:class:`django.core.files.File`, not Python's built-in file object.
  616
+You can construct a :class:`~django.core.files.File` from an existing
  617
+Python file object like this::
  618
+
  619
+    from django.core.files import File
  620
+    # Open an existing file using Python's built-in open()
  621
+    f = open('/tmp/hello.world')
  622
+    myfile = File(f)
  623
+
  624
+Or you can construct one from a Python string like this::
  625
+
  626
+    from django.core.files.base import ContentFile
  627
+    myfile = ContentFile("hello world")
  628
+
  629
+For more information, see :doc:`/topics/files`.
613 630
 
614 631
 .. method:: FieldFile.delete(save=True)
615 632
 

0 notes on commit 7fd113e

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