On 8 September 2010 22:15, maroxe <bachir...@gmail.com> wrote:
> Hi, 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). Form where
> this variable 'size' 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 att

FileField returns a wrapper around File which has a size attribute
[1]. In your template you're accessing that field. In your python code
you're trying to take "size" from a built-in type "file". To get the
value of the "file" field from your model you should use "self.file".
Unlike in some other OO languages, object attributes in methods are
not implicit.

[1]: 
http://docs.djangoproject.com/en/dev/ref/files/file/#django.core.files.File.size


-- 
Łukasz Rekucki

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to