Ticket #10305: T10305.diff

File T10305.diff, 4.5 KB (added by ctao, 7 years ago)
  • contrib/admin/options.py

    diff -r df0e563861bd contrib/admin/options.py
    a b  
    478478        ModelForm = self.get_form(request)
    479479        formsets = []
    480480        if request.method == 'POST':
    481             form = ModelForm(request.POST, request.FILES)
     481            if isinstance(ModelForm, ModelFormMetaclass):
     482                form = ModelForm(request.POST, request.FILES)
     483            else:
     484                form = ModelForm
    482485            if form.is_valid():
    483486                form_validated = True
    484487                new_object = self.save_form(request, form, change=False)
     
    509512                    continue
    510513                if isinstance(f, models.ManyToManyField):
    511514                    initial[k] = initial[k].split(",")
    512             form = ModelForm(initial=initial)
     515            if isinstance(ModelForm, ModelFormMetaclass):
     516                form = ModelForm(initial=initial)
     517            else:
     518                form = ModelForm
    513519            for FormSet in self.get_formsets(request):
    514520                formset = FormSet(instance=self.model())
    515521                formsets.append(formset)
     
    564570        ModelForm = self.get_form(request, obj)
    565571        formsets = []
    566572        if request.method == 'POST':
    567             form = ModelForm(request.POST, request.FILES, instance=obj)
     573            if isinstance(ModelForm, ModelFormMetaclass):
     574                form = ModelForm(request.POST, request.FILES, instance=obj)
     575            else:
     576                form = ModelForm
    568577            if form.is_valid():
    569578                form_validated = True
    570579                new_object = self.save_form(request, form, change=True)
     
    586595                self.log_change(request, new_object, change_message)
    587596                return self.response_change(request, new_object)
    588597        else:
    589             form = ModelForm(instance=obj)
     598            if isinstance(ModelForm, ModelFormMetaclass):
     599                form = ModelForm(instance=obj)
     600            else:
     601                form = ModelForm
    590602            for FormSet in self.get_formsets(request, obj):
    591603                formset = FormSet(instance=obj)
    592604                formsets.append(formset)
Back to Top