Ticket #15963: file_objects.diff
File file_objects.diff, 1.4 KB (added by , 14 years ago) |
---|
-
ref/models/fields.txt
613 613 data. 614 614 615 615 Takes two required arguments: ``name`` which is the name of the file, and 616 ``content`` which is a file-like object containing the file's contents.The617 optional ``save`` argument controls whether or not the instance is saved after618 the file has been altered. Defaults to ``True``. 616 ``content`` which is an object containing the file's contents. The 617 optional ``save`` argument controls whether or not the instance is 618 saved after the file has been altered. Defaults to ``True``. 619 619 620 Note that the ``content`` argument should be an instance of 621 :class:`django.core.files.File`, not Python's built-in file object. 622 You can construct a :class:`~django.core.files.File` from an existing 623 Python file object like this:: 624 625 from django.core.files import File 626 # Open an existing file using Python's built-in open() 627 f = open('/tmp/hello.world') 628 myfile = File(f) 629 630 Or you can construct one from a Python string like this:: 631 632 from django.core.files.base import ContentFile 633 myfile = ContentFile("hello world") 634 635 For more information, see :doc:`/topics/files`. 636 620 637 .. method:: FieldFile.delete(save=True) 621 638 622 639 Deletes the file associated with this instance and clears all attributes on