Hey, I am trying to do something very simple....

I have a downloads app in my django project. It has some fields like
file name, file path, file type and file size. What I wish is to take
the file path and get the file size via maybe getsize function in os,
but how can I write equivalent code for the same. I tried doing
something like this but it gave some errors( I am new at python as
well, so remind me of bad programming practices i had followed :P )


import .... #appropriate import satatements

FILETYPE_CHOICE=(
        ('Audio/Video','Audio/Video'),
        ('Text/Word','Text/Word'),
        ('source','Source Archives'),
        ('Binary','All other files go here!'),
)

class Files(models.Model):

        """Uploads area, all files to be ready for user use are put here"""


        filepath = models.FilePathField(_('Choose File'),path="/home/sanket/
Music")
        filedescription = models.CharField(_('File
Description'),max_length=100)
        filetype = models.CharField(_('File
Type'),max_length=1,choices=FILETYPE_CHOICE)

        fileuploadtime = models.DateTimeField(_('File Upload Time'))

        def __unicode__(self):
                return self.filepath

        class Admin:
                list_display  =
('filepath','filesize','fileuploaddate','fileuploadtime')
                list_filter   = ('fileuploaddate')

        def getSizeFromFilePath(filepath):
                return os.path.getsize(filepath)

        filesize = getSizeFromFilePath(filepath)

The problem is that the server grumbles about the path not being
available.... which seems logical, we havent put any till now :P.....
but then how do u accomplish such a task of modeling some of the
columns using the other column's information??

I got the above idea from the djangobook chapter on models. It didnt
talk much more detail... so I am rather helpless. Any help is
appreciated....

-snktagarwal

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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