如何使用South的DataMigration来更改Django模型ImageField实例的存储后端?

我正在尝试将一些模型ImageFields迁移到使用
django-storages
S3BotoStorage
存储后端。作为这个过程的一部分,我已经改变了我的Model的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
那么,如何在模型实例上移动/更改文件存储?     
已邀请:
因此,结果显示用于文件的特定存储不存储在数据库中。 “迁移”只是更改模型定义的问题,然后,在使用存储子系统API之外,只需将文件上载到新的存储位置即可。     
我会为你的问题看一个更像这样的系统。 http://github.com/seanbrant/django-queued-storage     

要回复问题请先登录注册