Code

Ticket #7667: save_file.diff

File save_file.diff, 1.1 KB (added by oggy, 6 years ago)
Line 
1Index: django/db/models/fields/__init__.py
2===================================================================
3--- django/db/models/fields/__init__.py (revision 7858)
4+++ django/db/models/fields/__init__.py (working copy)
5@@ -832,12 +832,14 @@
6     def save_file(self, new_data, new_object, original_object, change, rel, save=True):
7         upload_field_name = self.get_manipulator_field_names('')[0]
8         if new_data.get(upload_field_name, False):
9-            func = getattr(new_object, 'save_%s_file' % self.name)
10             if rel:
11                 file = new_data[upload_field_name][0]
12             else:
13                 file = new_data[upload_field_name]
14 
15+            if not file:
16+                return
17+
18             # Backwards-compatible support for files-as-dictionaries.
19             # We don't need to raise a warning because Model._save_FIELD_file will
20             # do so for us.
21@@ -846,6 +848,7 @@
22             except AttributeError:
23                 file_name = file['filename']
24 
25+            func = getattr(new_object, 'save_%s_file' % self.name)
26             func(file_name, file, save)
27 
28     def get_directory_name(self):