Code

Ticket #3635: models.diff

File models.diff, 1.0 KB (added by ludo@…, 7 years ago)
Line 
1Index: newforms/models.py
2===================================================================
3--- newforms/models.py  (revision 4637)
4+++ newforms/models.py  (working copy)
5@@ -36,13 +36,14 @@
6         raise ValueError("The %s could not be changed because the data didn't validate." % opts.object_name)
7     clean_data = form.clean_data
8     for f in opts.fields:
9-        if not f.editable or isinstance(f, models.AutoField):
10+        if not f.editable or isinstance(f, models.AutoField) or not f.name in clean_data:
11             continue
12         setattr(instance, f.name, clean_data[f.name])
13     if commit:
14         instance.save()
15         for f in opts.many_to_many:
16-            setattr(instance, f.attname, clean_data[f.name])
17+            if f.name in clean_data:
18+                setattr(instance, f.attname, clean_data[f.name])
19     # GOTCHA: If many-to-many data is given and commit=False, the many-to-many
20     # data will be lost. This happens because a many-to-many options cannot be
21     # set on an object until after it's saved. Maybe we should raise an