Ticket #3258: save_instance.2.patch
File save_instance.2.patch, 1.4 KB (added by , 18 years ago) |
---|
-
django/newforms/models.py
26 26 """ 27 27 Saves bound Form ``form``'s clean_data into model instance ``instance``. 28 28 29 Assumes ``form`` has a field for every non-AutoField database field in 30 ``instance``. If commit=True, then the changes to ``instance`` will be 31 saved to the database. Returns ``instance``. 29 If commit=True, then the changes to ``instance`` will be saved to the 30 database. Returns ``instance``. 32 31 """ 33 32 from django.db import models 34 33 opts = instance.__class__._meta … … 38 37 for f in opts.fields: 39 38 if not f.editable or isinstance(f, models.AutoField): 40 39 continue 41 setattr(instance, f.name, clean_data[f.name]) 40 if clean_data.has_key(f.name): 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 clean_data.has_key(f.name): 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