【发布时间】:2016-07-27 12:40:34
【问题描述】:
我有以下模型结构:
class BaseMovie(models.Model):
movie = models.FileField('Movie')
width = models.IntegerField('Width')
height = models.IntegerField('Height')
duration = models.FloatField('Duration')
class SpecialMovie(models.model):
base_movie = models.ForeignKey(BaseMovie, 'Base movie')
# some other stuff
背后的想法是我打算在几个模型中使用BaseMovie。
我的问题是:
如何在SpecialMovie 模型中设置特殊电影的上传位置?
我认为仅将元数据存储在BaseMovie 类中并在SpecialMovie 中使用适当的upload_to 函数的电影字段并不令人满意,因为我必须复制填充所有元数据的代码具有BaseMovie 外键的模型。
【问题讨论】:
-
Heroku 有一篇关于上传到 Amazon S3 的精彩文章:devcenter.heroku.com/articles/s3-upload-python
标签: django foreign-keys django-file-upload