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しかし、画像ファイルは単に古いバックエンドを使用して保存されるため、これは明らかに意図した効果をもたらしませんFieldFileFileField

では、モデルのインスタンスでファイル ストレージを移動/変更する方法は?

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 に答える