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?
source share