Ticket #5780: 5780-against-7875.patch

File 5780-against-7875.patch, 2.0 KB (added by Honza_Kral, 7 years ago)
  • django/contrib/admin/options.py

    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): 
    506506        obj = self.model()
    507507        if request.method == 'POST':
    508508            form = ModelForm(request.POST, request.FILES)
     509            if form.is_valid():
     510                obj = form.save(commit=False)
     511            else:
     512                obj = None
    509513            for FormSet in self.get_formsets(request):
    510514                inline_formset = FormSet(data=request.POST, files=request.FILES,
    511515                    instance=obj, save_as_new=request.POST.has_key("_saveasnew"))
    512516                inline_formsets.append(inline_formset)
    513             if all_valid(inline_formsets) and form.is_valid():
     517            if all_valid(inline_formsets) and obj:
    514518                return self.save_add(request, model, form, inline_formsets, '../%s/')
    515519        else:
    516520            form = ModelForm(initial=dict(request.GET.items()))
    class ModelAdmin(BaseModelAdmin): 
    568572        inline_formsets = []
    569573        if request.method == 'POST':
    570574            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
    571579            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)
    573581                inline_formsets.append(inline_formset)
    574582
    575583            if all_valid(inline_formsets) and form.is_valid():
Back to Top