diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index c18af62..fbd5e95 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
578 | 578 | """ |
579 | 579 | messages.info(request, message) |
580 | 580 | |
581 | | def save_form(self, request, form, change, commit=False): |
| 581 | def save_form(self, request, form, change): |
582 | 582 | """ |
583 | 583 | Given a ModelForm return an unsaved instance. ``change`` is True if |
584 | 584 | the object is being changed, and False if it's being added. |
585 | 585 | """ |
586 | | return form.save(commit=commit) |
| 586 | return form.save(commit=False) |
587 | 587 | |
588 | 588 | def save_model(self, request, obj, form, change): |
589 | 589 | """ |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
757 | 757 | if request.method == 'POST': |
758 | 758 | form = ModelForm(request.POST, request.FILES) |
759 | 759 | if form.is_valid(): |
760 | | # Save the object, even if inline formsets haven't been |
761 | | # validated yet. We need to pass the valid model to the |
762 | | # formsets for validation. If the formsets do not validate, we |
763 | | # will delete the object. |
764 | | new_object = self.save_form(request, form, change=False, commit=True) |
| 760 | new_object = self.save_form(request, form, change=False) |
765 | 761 | form_validated = True |
766 | 762 | else: |
767 | 763 | form_validated = False |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
778 | 774 | prefix=prefix, queryset=inline.queryset(request)) |
779 | 775 | formsets.append(formset) |
780 | 776 | if all_valid(formsets) and form_validated: |
| 777 | self.save_model(request, new_object, form, change=False) |
| 778 | form.save_m2m() |
781 | 779 | for formset in formsets: |
782 | 780 | self.save_formset(request, form, formset, change=False) |
783 | 781 | |
784 | 782 | self.log_addition(request, new_object) |
785 | 783 | return self.response_add(request, new_object) |
786 | | elif form_validated: |
787 | | # The form was valid, but formsets were not, so delete the |
788 | | # object we saved above. |
789 | | new_object.delete() |
790 | 784 | else: |
791 | 785 | # Prepare the dict of initial data from the request. |
792 | 786 | # We have to special-case M2Ms as a list of comma-separated PKs. |
diff --git a/django/forms/models.py b/django/forms/models.py
index 1203233..ac30e42 100644
a
|
b
|
class BaseModelForm(BaseForm):
|
254 | 254 | model_fields = set([f.name for f in self.instance._meta.fields]) |
255 | 255 | form_fields = set(self.fields) |
256 | 256 | excluded_fields = model_fields - form_fields |
| 257 | # HACK: Don't validate InlineForeignKeyField. If the parent model |
| 258 | # hasn't been saved, it won't have a value and will fail model |
| 259 | # field validation. See #12507 for details. |
| 260 | for fname in self.fields: |
| 261 | if isinstance(self.fields[fname], InlineForeignKeyField): |
| 262 | excluded_fields.add(fname) |
257 | 263 | failed_fields = set(self._errors.keys()) |
258 | 264 | self.instance.full_validate(exclude=failed_fields.union(excluded_fields)) |
259 | 265 | except ValidationError, e: |