diff options
| author | Karen Tracey <kmtracey@gmail.com> | 2008-11-04 19:54:28 +0000 |
|---|---|---|
| committer | Karen Tracey <kmtracey@gmail.com> | 2008-11-04 19:54:28 +0000 |
| commit | 8e4827e5068ebe26e8669ffa676b7d6764fbb00d (patch) | |
| tree | 120f161a12c20776e5064487ba8614c5897aecdf /django | |
| parent | 4563060093ad6d30c76b62dce4d822f9426eaef2 (diff) | |
[1.0.X] Fixed #9418 -- When saving a model form, defer saving of file-type fields until after other fields, so that callable upload_to methods can use data from the other fields. Thanks to Bernd Schlapsi for the report and initial patch.
[9334] from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9335 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/forms/models.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index 99f7ef5bfb..cd2191307e 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -41,6 +41,7 @@ def save_instance(form, instance, fields=None, fail_message='saved', raise ValueError("The %s could not be %s because the data didn't" " validate." % (opts.object_name, fail_message)) cleaned_data = form.cleaned_data + file_field_list = [] for f in opts.fields: if not f.editable or isinstance(f, models.AutoField) \ or not f.name in cleaned_data: @@ -49,7 +50,16 @@ def save_instance(form, instance, fields=None, fail_message='saved', continue if exclude and f.name in exclude: continue + # Defer saving file-type fields until after the other fields, so a + # callable upload_to can use the values from other fields. + if isinstance(f, models.FileField): + file_field_list.append(f) + else: + f.save_form_data(instance, cleaned_data[f.name]) + + for f in file_field_list: f.save_form_data(instance, cleaned_data[f.name]) + # Wrap up the saving of m2m data as a function. def save_m2m(): opts = instance._meta |
