Ticket #5780: 5780-against-7925.patch

File 5780-against-7925.patch, 2.0 KB (added by jakub_vysoky, 16 years ago)
  • django/contrib/admin/options.py

    commit 483ef288c31810eb0c061aa1bef25ee92d92b5b8
    Author: Jakub Vysoky <jakub@borka.cz>
    Date:   Tue Jul 15 13:41:39 2008 +0200
    
        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 07f29ac..8e7a8eb 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, form, inline_formsets, '../%s/')
    515519        else:
    516520            form = ModelForm(initial=dict(request.GET.items()))
    class ModelAdmin(BaseModelAdmin):  
    569573        inline_formsets = []
    570574        if request.method == 'POST':
    571575            form = ModelForm(request.POST, request.FILES, instance=obj)
     576            if form.is_valid():
     577                new_obj = form.save( commit=False )
     578            else:
     579                new_obj = obj
    572580            for FormSet in self.get_formsets(request, obj):
    573                 inline_formset = FormSet(request.POST, request.FILES, instance=obj)
     581                inline_formset = FormSet(data=request.POST, files=request.FILES, instance=new_obj)
    574582                inline_formsets.append(inline_formset)
    575583
    576584            if all_valid(inline_formsets) and form.is_valid():
Back to Top