Repository: akvo/akvo-rsr

Issue:
Bug: Creating a new org with a logo doesn't work
### What were you doing?

In the RSR admin, open "Organisations" and click on "Ad rganisation".
Fill out the required information and add a logo of your choice.
Finally, click on "Save".

# Returned

An HTTP 500 error

### What should've happened?

An organisation should've been created with the data entered.

### My environment

## Desktop

OS: NixOS

Browser: Firefox 

Version: 95.0.2



### Additional context

The stack in the backend

```
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/django/views.py", line 67, in sentry_wrapped_callback
    return callback(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/contrib/admin/options.py", line 616, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/var/akvo/rsr/code/akvo/rsr/admin.py", line 351, in add_view
    self.save_model(request, new_object, form, False)
  File "/usr/local/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1099, in save_model
    obj.save()
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 739, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 787, in save_base
    post_save.send(
  File "/usr/local/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 180, in send
    return [
  File "/usr/local/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 181, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/var/akvo/rsr/code/akvo/rsr/signals.py", line 100, in change_name_of_file_on_create
    save_image(img, img_name)
  File "/var/akvo/rsr/code/akvo/utils.py", line 532, in save_image
    img.instance.save(update_fields=['photo'])
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 722, in save
    raise ValueError(
ValueError: The following fields do not exist in this model, are m2m fields, or are non-concrete fields: photo
```


Discussion:

Resolving patch:
diff --git a/akvo/rsr/signals.py b/akvo/rsr/signals.py
--- a/akvo/rsr/signals.py
+++ b/akvo/rsr/signals.py
@@ -97,7 +97,7 @@ def change_name_of_file_on_create(sender, **kwargs):
                         datetime.now().strftime("%Y-%m-%d_%H.%M.%S"),
                         os.path.splitext(img.name)[1],
                     )
-                    save_image(img, img_name)
+                    save_image(img, img_name, f.name)
                     # Create thumbnail for use in reports
                     if sender == ProjectUpdate:
                         get_report_thumbnail(img)
diff --git a/akvo/utils.py b/akvo/utils.py
--- a/akvo/utils.py
+++ b/akvo/utils.py
@@ -523,13 +523,13 @@ def maybe_decimal(value):
         return None
 
 
-def save_image(img, name):
+def save_image(img, name, field_name):
     if isinstance(img.storage, GoogleCloudStorage):
         new_name = img.field.generate_filename(img.instance, name)
         blob = img.storage.bucket.blob(img.name)
         img.storage.bucket.rename_blob(blob, new_name)
         img.name = new_name
-        img.instance.save(update_fields=['photo'])
+        img.instance.save(update_fields=[field_name])
     else:
         img.save(name, img)
 


Test patch: