Ticket #4312: models.diff
File models.diff, 1.8 KB (added by , 18 years ago) |
---|
-
django/newforms/models.py
12 12 __all__ = ('save_instance', 'form_for_model', 'form_for_instance', 'form_for_fields', 13 13 'ModelChoiceField', 'ModelMultipleChoiceField') 14 14 15 def save_instance(form, instance, fields=None, fail_message='saved', commit=True):15 def save_instance(form, instance, fields=None, defaults=None, fail_message='saved', commit=True): 16 16 """ 17 17 Saves bound Form ``form``'s cleaned_data into model instance ``instance``. 18 18 … … 31 31 if fields and f.name not in fields: 32 32 continue 33 33 setattr(instance, f.name, cleaned_data[f.name]) 34 if defaults: 35 for f in defaults: 36 setattr(instance, f, defaults[f]) 34 37 if commit: 35 38 instance.save() 36 39 for f in opts.many_to_many: … … 46 49 47 50 def make_model_save(model, fields, fail_message): 48 51 "Returns the save() method for a Form." 49 def save(self, commit=True ):50 return save_instance(self, model(), fields, fail_message, commit)52 def save(self, commit=True, defaults=None): 53 return save_instance(self, model(), fields, defaults, fail_message, commit) 51 54 return save 52 55 53 56 def make_instance_save(instance, fields, fail_message): 54 57 "Returns the save() method for a Form." 55 def save(self, commit=True ):56 return save_instance(self, instance, fields, fail_message, commit)58 def save(self, commit=True, defaults=None): 59 return save_instance(self, instance, fields, defaults, fail_message, commit) 57 60 return save 58 61 59 62 def form_for_model(model, form=BaseForm, fields=None, formfield_callback=lambda f: f.formfield()):