Code

Ticket #10305: T10305.diff

File T10305.diff, 4.5 KB (added by ctao, 5 years ago)
Line 
1diff -r df0e563861bd contrib/admin/options.py
2--- a/contrib/admin/options.py  Wed Sep 24 15:13:01 2008 -0400
3+++ b/contrib/admin/options.py  Thu Feb 19 14:56:48 2009 -0500
4@@ -478,7 +478,10 @@
5         ModelForm = self.get_form(request)
6         formsets = []
7         if request.method == 'POST':
8-            form = ModelForm(request.POST, request.FILES)
9+            if isinstance(ModelForm, ModelFormMetaclass):
10+                form = ModelForm(request.POST, request.FILES)
11+            else:
12+                form = ModelForm
13             if form.is_valid():
14                 form_validated = True
15                 new_object = self.save_form(request, form, change=False)
16@@ -509,7 +512,10 @@
17                     continue
18                 if isinstance(f, models.ManyToManyField):
19                     initial[k] = initial[k].split(",")
20-            form = ModelForm(initial=initial)
21+            if isinstance(ModelForm, ModelFormMetaclass):
22+                form = ModelForm(initial=initial)
23+            else:
24+                form = ModelForm
25             for FormSet in self.get_formsets(request):
26                 formset = FormSet(instance=self.model())
27                 formsets.append(formset)
28@@ -564,7 +570,10 @@
29         ModelForm = self.get_form(request, obj)
30         formsets = []
31         if request.method == 'POST':
32-            form = ModelForm(request.POST, request.FILES, instance=obj)
33+            if isinstance(ModelForm, ModelFormMetaclass):
34+                form = ModelForm(request.POST, request.FILES, instance=obj)
35+            else:
36+                form = ModelForm
37             if form.is_valid():
38                 form_validated = True
39                 new_object = self.save_form(request, form, change=True)
40@@ -586,7 +595,10 @@
41                 self.log_change(request, new_object, change_message)
42                 return self.response_change(request, new_object)
43         else:
44-            form = ModelForm(instance=obj)
45+            if isinstance(ModelForm, ModelFormMetaclass):
46+                form = ModelForm(instance=obj)
47+            else:
48+                form = ModelForm
49             for FormSet in self.get_formsets(request, obj):
50                 formset = FormSet(instance=obj)
51                 formsets.append(formset)