summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-03-31 09:47:32 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-03-31 09:47:32 +0000
commit6a5deb6bc0ca6260b2af374583737c3c63a3037b (patch)
treef8b0028ce834e57734eb0aab534d0446119a021a
parent1ccdcbf765f146040f8cb2130b4b20fc8cd5ff90 (diff)
Fixed #3635 -- Fixed KeyError problem in newforms.model.save_instance().
Thanks, ludo@qix.it. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4878 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/newforms/models.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/newforms/models.py b/django/newforms/models.py
index 616c7141e7..a60002b705 100644
--- a/django/newforms/models.py
+++ b/django/newforms/models.py
@@ -36,13 +36,14 @@ def save_instance(form, instance, commit=True):
raise ValueError("The %s could not be changed because the data didn't validate." % opts.object_name)
clean_data = form.clean_data
for f in opts.fields:
- if not f.editable or isinstance(f, models.AutoField):
+ if not f.editable or isinstance(f, models.AutoField) or not f.name in clean_data:
continue
setattr(instance, f.name, clean_data[f.name])
if commit:
instance.save()
for f in opts.many_to_many:
- setattr(instance, f.attname, clean_data[f.name])
+ if f.name in clean_data:
+ setattr(instance, f.attname, clean_data[f.name])
# GOTCHA: If many-to-many data is given and commit=False, the many-to-many
# data will be lost. This happens because a many-to-many options cannot be
# set on an object until after it's saved. Maybe we should raise an