4

我正在尝试将一些模型 ImageFields 迁移到使用S3BotoStorage来自django-storages. 作为此过程的一部分,我已更改模型的 ImageField 声明以包含storage=instance_of_s3botostorage参数,并且将图像保存到 ImageField 属性的模型的新实例现在按预期存储在 S3 中。

我也尝试将现有模型实例移动到将它们的数据存储在 S3 中,所以写了一个这样的 South DataMigration:

def forwards(self, orm):
    "upload ImageField file to S3 if it's not already in there"
    for mymodel in orm.MyModel.objects.all():
        if mymodel.logo_image and not isinstance(mymodel.logo_image.storage, S3BotoStorage):
            print "uploading %s to S3" % mymodel.logo_image
            file_contents = ContentFile(mymodel.logo_image.read())
            mymodel.logo_image.save(mymodel.logo_image.name, file_contents)
            mymodel.save()

但这显然没有达到预期的效果,因为图像文件只是使用旧storage后端保存的——考虑到 save() 实际上是FieldFile属于FileField

那么,如何移动/更改模型实例上的文件存储?

4

2 回答 2

4

因此,事实证明用于文件的特定存储没有存储在数据库中。“迁移”只是更改模型定义的问题,然后在使用存储子系统 API 之外,只需将文件上传到新的存储位置。

于 2010-08-23T05:58:33.287 回答
0

对于您的问题,我会看一个更像这样的系统。http://github.com/seanbrant/django-queued-storage

于 2010-08-23T07:28:57.800 回答