Code

Ticket #4727: newforms-admin-5559-allow-form-base-override.diff

File newforms-admin-5559-allow-form-base-override.diff, 1.8 KB (added by Honza Král <Honza.Kral@…>, 7 years ago)
Line 
1Index: django/contrib/admin/options.py
2===================================================================
3--- django/contrib/admin/options.py     (revision 5559)
4+++ django/contrib/admin/options.py     (working copy)
5@@ -162,6 +162,7 @@
6     filter_vertical = ()
7     filter_horizontal = ()
8     inlines = []
9+    base_form = forms.BaseForm
10 
11     def __init__(self, model):
12         self.model = model
13@@ -412,7 +413,7 @@
14             # Object list will give 'Permission Denied', so go back to admin home
15             post_url = '../../../'
16 
17-        ModelForm = forms.form_for_model(model, formfield_callback=self.formfield_for_dbfield)
18+        ModelForm = forms.form_for_model(model, form=self.base_form, formfield_callback=self.formfield_for_dbfield)
19 
20         inline_formsets = []
21         if request.POST:
22@@ -465,7 +466,7 @@
23         if request.POST and request.POST.has_key("_saveasnew"):
24             return self.add_view(request, form_url='../../add/')
25 
26-        ModelForm = forms.form_for_instance(obj, formfield_callback=self.formfield_for_dbfield)
27+        ModelForm = forms.form_for_instance(obj, form=self.base_form, formfield_callback=self.formfield_for_dbfield)
28 
29         inline_formsets = []
30         if request.POST:
31Index: django/contrib/admin/templates/admin/change_form.html
32===================================================================
33--- django/contrib/admin/templates/admin/change_form.html       (revision 5559)
34+++ django/contrib/admin/templates/admin/change_form.html       (working copy)
35@@ -38,6 +38,7 @@
36 {% if adminform.form.errors %}
37     <p class="errornote">
38     {% blocktrans count adminform.form.errors.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
39+    {{ adminform.form.non_field_errors }}
40     </p>
41 {% endif %}
42