How can I use Southern DataMigration to modify the repository database of an instance of ImageField Django model?

I am trying to migrate some ImageFields models using the S3BotoStorage backend with django-storages . As part of this process, I modified the Model ImageField declaration to include the storage=instance_of_s3botostorage argument, and new instances of my model that store the image in the ImageField attribute are now saved in S3 - as intended.

I tried to move existing model instances to store my data in S3, so I wrote Southern DataMigration as follows:

 def forwards(self, orm): "upload ImageField file to S3 if it 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() 

but this clearly does not have the intended effect, because the image file is simply saved using the old storage backend, which makes sense considering that save () is actually a FieldFile method owned by FileField

So, how to move / modify file storage in the model instance?

+4
source share
2 answers

So, it turns out that the specific storage used for files is not stored in the database. "migration" is just a matter of changing the model definition, except for using the storage subsystem API, just upload files to new storage locations.

+4
source

I would look at a system more similar to this problem. http://github.com/seanbrant/django-queued-storage

0
source

All Articles