Ticket #15963: file_objects.diff

File file_objects.diff, 1.4 KB (added by Ethan Jucovy, 13 years ago)
  • ref/models/fields.txt

     
    613613data.
    614614
    615615Takes 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. The
    617 optional ``save`` argument controls whether or not the instance is saved after
    618 the file has been altered. Defaults to ``True``.
     616``content`` which is an object containing the file's contents. The
     617optional ``save`` argument controls whether or not the instance is
     618saved after the file has been altered. Defaults to ``True``.
    619619
     620Note that the ``content`` argument should be an instance of
     621:class:`django.core.files.File`, not Python's built-in file object.
     622You can construct a :class:`~django.core.files.File` from an existing
     623Python 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
     630Or 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
     635For more information, see :doc:`/topics/files`.
     636
    620637.. method:: FieldFile.delete(save=True)
    621638
    622639Deletes the file associated with this instance and clears all attributes on
Back to Top