﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11597	Documentation for File object is misleading	amenasse@…	nobody	"I found the documentation for the File object misleading.

From http://docs.djangoproject.com/en/dev/topics/files/#topics-files

""
If you need to construct a File yourself, the easiest way is to create one using a Python built-in file object:
{{{


>>> from django.core.files import File

# Create a Python file object using open()
>>> f = open('/tmp/hello.world', 'w')
>>> myfile = File(f)

}}}

Now you can use any of the File attributes and methods documented in The File object.""

The last statement is misleading because i found i couldn't:



http://docs.djangoproject.com/en/dev/ref/files/file/#ref-files-file 

describes attributes such as url and path available to a File object

{{{
 >>> myfile.url
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
AttributeError: 'File' object has no attribute 'url'
>>> myfile.path
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>

>>> 
}}}

i'm using svn release and docs.

as a side note , it would be really nice if things did work the way i understood from the docs. 

My particular case requires me to create a File object that is not tied to a database field but has path and url attributes just like a FileField  so from the templates i can do:

{{ object.url }} 

For now i am hacking around this with my own class that provides these methods. 


{{{
 class FakeFileField(object):
   
     def __init__(self,path):
       self.storage = FileSystemStorage()
       self._path = path

     def _get_url(self):
      return self.storage.url(self._path)

    def _get_path(self):
      return self.storage.path(self._path)

    .
    .
}}}


Thanks 
Anthony
"		closed	Documentation	dev		fixed	File url path		Accepted	0	0	0	0	0	0
