Ticket #10271: admin-formset-inheritance.diff

File admin-formset-inheritance.diff, 2.7 KB (added by Alex Gaynor, 16 years ago)

the reporter says this patch fixes it, needs tests

  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index ed41c7f..7c7d73d 100644
    a b class ModelAdmin(BaseModelAdmin):  
    522522            else:
    523523                form_validated = False
    524524                new_object = self.model()
    525             for FormSet in self.get_formsets(request):
     525            for idx, FormSet in enumerate(self.get_formsets(request)):
    526526                formset = FormSet(data=request.POST, files=request.FILES,
    527527                                  instance=new_object,
    528                                   save_as_new=request.POST.has_key("_saveasnew"))
     528                                  save_as_new=request.POST.has_key("_saveasnew"),
     529                                  prefix="form-%s" % idx)
    529530                formsets.append(formset)
    530531            if all_valid(formsets) and form_validated:
    531532                self.save_model(request, new_object, form, change=False)
    class ModelAdmin(BaseModelAdmin):  
    547548                if isinstance(f, models.ManyToManyField):
    548549                    initial[k] = initial[k].split(",")
    549550            form = ModelForm(initial=initial)
    550             for FormSet in self.get_formsets(request):
    551                 formset = FormSet(instance=self.model())
     551            for idx, FormSet in enumerate(self.get_formsets(request)):
     552                formset = FormSet(instance=self.model(), prefix="form-%s" % idx)
    552553                formsets.append(formset)
    553554       
    554555        adminForm = helpers.AdminForm(form, list(self.get_fieldsets(request)), self.prepopulated_fields)
    class ModelAdmin(BaseModelAdmin):  
    608609            else:
    609610                form_validated = False
    610611                new_object = obj
    611             for FormSet in self.get_formsets(request, new_object):
     612            for idx, FormSet in enumerate(self.get_formsets(request, new_object)):
    612613                formset = FormSet(request.POST, request.FILES,
    613                                   instance=new_object)
     614                                  instance=new_object, prefix="form-%s" % idx)
    614615                formsets.append(formset)
    615616           
    616617            if all_valid(formsets) and form_validated:
    class ModelAdmin(BaseModelAdmin):  
    625626       
    626627        else:
    627628            form = ModelForm(instance=obj)
    628             for FormSet in self.get_formsets(request, obj):
    629                 formset = FormSet(instance=obj)
     629            for idx, FormSet in enumerate(self.get_formsets(request, obj)):
     630                formset = FormSet(instance=obj, prefix="form-%s" % idx)
    630631                formsets.append(formset)
    631632       
    632633        adminForm = helpers.AdminForm(form, self.get_fieldsets(request, obj), self.prepopulated_fields)
Back to Top