Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 6a5deb6bc0ca6260b2af374583737c3c63a3037b 1 parent 1ccdcbf
Malcolm Tredinnick authored March 31, 2007

Showing 1 changed file with 3 additions and 2 deletions. Show diff stats Hide diff stats

  1. 5  django/newforms/models.py
5  django/newforms/models.py
@@ -36,13 +36,14 @@ def save_instance(form, instance, commit=True):
36 36
         raise ValueError("The %s could not be changed because the data didn't validate." % opts.object_name)
37 37
     clean_data = form.clean_data
38 38
     for f in opts.fields:
39  
-        if not f.editable or isinstance(f, models.AutoField):
  39
+        if not f.editable or isinstance(f, models.AutoField) or not f.name in clean_data:
40 40
             continue
41 41
         setattr(instance, f.name, clean_data[f.name])
42 42
     if commit:
43 43
         instance.save()
44 44
         for f in opts.many_to_many:
45  
-            setattr(instance, f.attname, clean_data[f.name])
  45
+            if f.name in clean_data:
  46
+                setattr(instance, f.attname, clean_data[f.name])
46 47
     # GOTCHA: If many-to-many data is given and commit=False, the many-to-many
47 48
     # data will be lost. This happens because a many-to-many options cannot be
48 49
     # set on an object until after it's saved. Maybe we should raise an

0 notes on commit 6a5deb6

Please sign in to comment.
Something went wrong with that request. Please try again.