Reputation: 2127
There is something I don't get in Django template system. I have a FileField in my model called myfile. If I pass an instance of my model to a template, I can access file.size (this is an example). Where does the file.size
variable come from? It's not part of the FileField class as far as I know. A small test:
def save(self):
super(UploadItem, self).save()
import logging; logging.debug(file.size)
This snippet generates this error: type object 'file' has no attribute 'size'
Is Django doing this via magic of some kind?
Upvotes: 0
Views: 150
Reputation: 391854
If you want to retrieve the upload file's on-disk filename, or a URL that refers to that file, or the file's size, you can use the
name
,url
andsize
attributes; see Managing files.
http://docs.djangoproject.com/en/1.2/ref/models/fields/#filefield
http://docs.djangoproject.com/en/1.2/topics/files/
Upvotes: 2