commit 321ba035c532769579e109446f1fb0eef18ef214
Author: Honza Král <Honza.Kral@gmail.com>
Date: Mon Jan 28 22:13:54 2008 +0100
Passing the unsaved created object to inline formsets for validation.
http://code.djangoproject.com/ticket/5780
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 4c7d83b..a6e037d 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
506 | 506 | obj = self.model() |
507 | 507 | if request.method == 'POST': |
508 | 508 | form = ModelForm(request.POST, request.FILES) |
| 509 | if form.is_valid(): |
| 510 | obj = form.save(commit=False) |
| 511 | else: |
| 512 | obj = None |
509 | 513 | for FormSet in self.get_formsets(request): |
510 | 514 | inline_formset = FormSet(data=request.POST, files=request.FILES, |
511 | 515 | instance=obj, save_as_new=request.POST.has_key("_saveasnew")) |
512 | 516 | inline_formsets.append(inline_formset) |
513 | | if all_valid(inline_formsets) and form.is_valid(): |
| 517 | if all_valid(inline_formsets) and obj: |
514 | 518 | return self.save_add(request, model, form, inline_formsets, '../%s/') |
515 | 519 | else: |
516 | 520 | form = ModelForm(initial=dict(request.GET.items())) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
568 | 572 | inline_formsets = [] |
569 | 573 | if request.method == 'POST': |
570 | 574 | form = ModelForm(request.POST, request.FILES, instance=obj) |
| 575 | if form.is_valid(): |
| 576 | new_obj = form.save( commit=False ) |
| 577 | else: |
| 578 | new_obj = obj |
571 | 579 | for FormSet in self.get_formsets(request, obj): |
572 | | inline_formset = FormSet(request.POST, request.FILES, instance=obj) |
| 580 | inline_formset = FormSet(data=request.POST, files=request.FILES, instance=new_obj) |
573 | 581 | inline_formsets.append(inline_formset) |
574 | 582 | |
575 | 583 | if all_valid(inline_formsets) and form.is_valid(): |