开发者

Django. self.file.path does not include upload_to subdirectory

I'm trying to get some information from a file before the Model is saved to the database. So basically what i'm doing it is overwriting method save like follow:

class Media(models.Model):
    file = models.FileField(upload_to='audio/')

    def save(self, *args, **kwargs):
        if not self.id:
             print self.file.path
        super(Media, self).save(*args, **kwargs)

But when I print attribute self.file.path is does not include "audio/" subdirectory. Instead of this '/Users/me/Dropbox/Public/music/audio/myfile.ext'

I'm getting '/Users/me/Dropbox/Public/music/myfile.ext'

The 开发者_StackOverflowfile is located where it suppose to be. In '/Users/me/Dropbox/Public/music/audio/myfile.ext'

My

MEDIA_ROOT = '/Users/me/Dropbox/Public/music'

What I've missed?

UPDATE: Looks like it add 'audio/' to the path after it save the model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜