Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Display non_field_errors of inline forms in the admin. This was a pre…

…sentation bug.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9243 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5e5af8a8aae3c860f2b9463b2a5df713fc53d6d0 1 parent ae43d11
Brian Rosner authored October 21, 2008
10  django/contrib/admin/helpers.py
@@ -129,6 +129,16 @@ def __init__(self, formset, form, fieldsets, prepopulated_fields, original):
129 129
             self.original.content_type_id = ContentType.objects.get_for_model(original).pk
130 130
         self.show_url = original and hasattr(original, 'get_absolute_url')
131 131
         super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields)
  132
+    
  133
+    def field_count(self):
  134
+        # tabular.html uses this function for colspan value.
  135
+        num_of_fields = 1 # always has at least one field
  136
+        num_of_fields += len(self.fieldsets[0][1]["fields"])
  137
+        if self.formset.can_order:
  138
+            num_of_fields += 1
  139
+        if self.formset.can_delete:
  140
+            num_of_fields += 1
  141
+        return num_of_fields
132 142
 
133 143
     def pk_field(self):
134 144
         return AdminField(self.form, self.formset._pk_field.name, False)
3  django/contrib/admin/options.py
@@ -585,6 +585,7 @@ def change_view(self, request, object_id, extra_context=None):
585 585
                 change_message = self.construct_change_message(request, form, formsets)
586 586
                 self.log_change(request, new_object, change_message)
587 587
                 return self.response_change(request, new_object)
  588
+                
588 589
         else:
589 590
             form = ModelForm(instance=obj)
590 591
             for FormSet in self.get_formsets(request, obj):
@@ -600,7 +601,7 @@ def change_view(self, request, object_id, extra_context=None):
600 601
             inline_admin_formset = helpers.InlineAdminFormSet(inline, formset, fieldsets)
601 602
             inline_admin_formsets.append(inline_admin_formset)
602 603
             media = media + inline_admin_formset.media
603  
-
  604
+        
604 605
         context = {
605 606
             'title': _('Change %s') % force_unicode(opts.verbose_name),
606 607
             'adminform': adminForm,
1  django/contrib/admin/templates/admin/edit_inline/stacked.html
@@ -12,6 +12,7 @@
12 12
   {% if inline_admin_form.show_url %}
13 13
   <p><a href="../../../r/{{ inline_admin_form.original.content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a></p>
14 14
   {% endif %}
  15
+  {% if inline_admin_form.form.non_field_errors %}{{ inline_admin_form.form.non_field_errors }}{% endif %}
15 16
 
16 17
   {% for fieldset in inline_admin_form %}
17 18
     {% include "admin/includes/fieldset.html" %}
4  django/contrib/admin/templates/admin/edit_inline/tabular.html
@@ -16,7 +16,9 @@
16 16
      </tr></thead>
17 17
    
18 18
      {% for inline_admin_form in inline_admin_formset %}
19  
-                   
  19
+        {% if inline_admin_form.form.non_field_errors %}
  20
+        <tr><td colspan="{{ inline_admin_form.field_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
  21
+        {% endif %}
20 22
         <tr class="{% cycle row1,row2 %} {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}">
21 23
 
22 24
         <td class="original">

0 notes on commit 5e5af8a

Please sign in to comment.
Something went wrong with that request. Please try again.