Issue #224 new

Django-storages save() problem

David Suilea
created an issue
form = Form(request.POST, request.FILES)

if form.is_valid():
   new_file = form.save(commit=False)                                                                           
   new_file.client = client

   if client.location == "US":
        new_file.file_instance.storage = S3BotoStorage(bucket="us")

   # Here new_file.file_instance.storage.bucket.name is us
   new_file.save()
   # Here new_file.file_instance.storage.bucket.name is eu

What I'm trying to do : I'm trying, at runtime, to decide if I'm gonna use the default bucket or the us bucket to save a file in. Using : django storages + boto and amazon aws s3

Extra information : I have a default AWS_STORAGE_BUCKET_NAME set to eu

Problem encountered : If I try to save the file on the us server, the file gets saved on the us bucket but the file gets saved in the database with the default bucket value, so when I try to load the file, it tries to get the file from the eu bucket. As seen on line 12 and 14, it seems that the save method overwrites the value that I provide in line 10

Comments (0)

  1. Log in to comment