On Sun, May 3, 2009 at 9:15 AM, Sanket Agarwal <snktagar...@gmail.com>wrote:
> > <snip> > 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) > A few things. One if you want a method to be available outside a class, the first argument is always 'self', which is the class instance itself. That is why the filepath isn't working there. Second to add a property to a class you need to declare it as a property, otherwise you are changing the class itself, not the instance. Take a look at the class documentation: http://docs.python.org/tutorial/classes.html and the property builtin: http://docs.python.org/library/functions.html#property Other than that, that appears to be the right idea to accomplish what you are looking for. I hope that helps, Michael --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---