Ticket #5780: 5780.diff

File 5780.diff, 1.7 KB (added by Honza Král, 17 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 0365228..424c512 100644
    a b class ModelAdmin(BaseModelAdmin):  
    495495        inline_formsets = []
    496496        if request.method == 'POST':
    497497            form = ModelForm(request.POST, request.FILES)
     498            if form.is_valid():
     499                obj = form.save(commit=False)
     500            else:
     501                obj = None
    498502            for FormSet in self.formsets_add(request):
    499                 inline_formset = FormSet(data=request.POST, files=request.FILES)
     503                inline_formset = FormSet(instance=obj, data=request.POST, files=request.FILES)
    500504                inline_formsets.append(inline_formset)
    501             if all_valid(inline_formsets) and form.is_valid():
     505            if all_valid(inline_formsets) and obj:
    502506                return self.save_add(request, model, form, inline_formsets, '../%s/')
    503507        else:
    504508            form = ModelForm(initial=request.GET)
    class ModelAdmin(BaseModelAdmin):  
    554558        inline_formsets = []
    555559        if request.method == 'POST':
    556560            form = ModelForm(request.POST, request.FILES)
     561            if form.is_valid():
     562                new_obj = form.save( commit=False )
     563            else:
     564                new_obj = obj
     565
    557566            for FormSet in self.formsets_change(request, obj):
    558                 inline_formset = FormSet(obj, request.POST, request.FILES)
     567                inline_formset = FormSet(new_obj, request.POST, request.FILES)
    559568                inline_formsets.append(inline_formset)
    560569
    561570            if all_valid(inline_formsets) and form.is_valid():
Back to Top