Ticket #12749: 12206.patch
File 12206.patch, 2.1 KB (added by , 15 years ago) |
---|
-
django/trunk/django/contrib/admin/options.py
580 580 messages.info(request, message) 581 581 582 def save_form(self, request, form, change , commit=False):582 def save_form(self, request, form, change): 583 583 """ 584 584 Given a ModelForm return an unsaved instance. ``change`` is True if 585 585 the object is being changed, and False if it's being added. 586 586 """ 587 return form.save(commit= commit)587 return form.save(commit=False) 588 588 589 589 def save_model(self, request, obj, form, change): … … 759 759 form = ModelForm(request.POST, request.FILES) 760 760 if form.is_valid(): 761 # Save the object, even if inline formsets haven't been 762 # validated yet. We need to pass the valid model to the 763 # formsets for validation. If the formsets do not validate, we 764 # will delete the object. 765 new_object = self.save_form(request, form, change=False, commit=True) 761 new_object = self.save_form(request, form, change=False) 766 762 form_validated = True 767 763 else: … … 780 776 formsets.append(formset) 781 777 if all_valid(formsets) and form_validated: 778 self.save_model(request, new_object, form, change=False) 779 form.save_m2m() 782 780 for formset in formsets: 783 781 self.save_formset(request, form, formset, change=False) … … 785 783 self.log_addition(request, new_object) 786 784 return self.response_add(request, new_object) 787 elif form_validated:788 # The form was valid, but formsets were not, so delete the789 # object we saved above.790 new_object.delete()791 785 else: 792 786 # Prepare the dict of initial data from the request.