Opened 9 years ago

Closed 9 years ago

#7508 closed (wontfix)

Using edit_inline = models.TABULAR doesn't show any validation errors in the admin.

Reported by: Remco Wendt Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Disclaimer: this issue will be resolved with the upcoming newforms-admin branch. It is here to provide a work-around to help people running into a similar case.

If you have a model which is editted through a different model using edit_inline like:

class Article(models.Model):
    title = models.CharField('Title of article', max_length=20, blank=False)

class Author(models.Model):
    article = models.ForeignKey(Article, edit_inline=models.TABULAR)
    first_name = models.CharField('First name of editor', max_length=20, blank=False, core=True)

Then adding a new article and not filling in the Author name generates a ValidationError. But because models.TABULAR is used the ValidationError will not show, thus making it hard for users to correct their errors. This problem will be fixed in newforms-admin. But as a work around one can add the following (adapted) edit_inline_tabular.html to their templates/admin directory (the directory that overrides the templates provided by contrib.admin itself). Now validation errors will show.

{% load admin_modify %}
<fieldset class="module">
   <h2>{{ bound_related_object.relation.opts.verbose_name_plural|capfirst }}</h2><table>
   {% for fw in bound_related_object.field_wrapper_list %}
      {% if fw.needs_header %}
         <th{{ fw.header_class_attribute }}>{{ fw.field.verbose_name|capfirst }}</th>
      {% endif %}
   {% endfor %}
   {% for fcw in bound_related_object.form_field_collection_wrappers %}
      {% if change %}{% if original_row_needed %}
         {% if fcw.obj.original %}
            <tr class="row-label {% cycle row1,row2 %}"><td colspan="{{ num_headers }}"><strong>{{ fcw.obj.original }}</strong></tr>
         {% endif %}
      {% endif %}{% endif %}
      {% if fcw.obj.errors %}
         <tr class="errorlist"><td colspan="{{ num_headers }}">
            {{ fcw.obj.html_combined_error_list }}
      {% endif %}
      <tr class="{% cycle row1,row2 %}">
      {% for bound_field in fcw.bound_fields %}
         {% if not bound_field.hidden %}
         <td {{ bound_field.cell_class_attribute }}>
             {{ bound_field.html_error_list }}
            {% field_widget bound_field %}
         {% endif %}
      {% endfor %}
      {% if bound_related_object.show_url %}<td>
         {% if fcw.obj.original %}<a href="/r/{{ fcw.obj.original.content_type_id }}/{{ }}/">View on site</a>{% endif %}
      </td>{% endif %}

   {% endfor %} </table>

   {% for fcw in bound_related_object.form_field_collection_wrappers %}
      {% for bound_field in fcw.bound_fields %}
         {% if bound_field.hidden %}
            {% field_widget bound_field %}
         {% endif %}
      {% endfor %}
   {% endfor %}

See also the attachment for a downloadable version of the above file.

Attachments (1)

edit_inline_tabular.html (1.7 KB) - added by Remco Wendt 9 years ago.
The mentioned file

Download all attachments as: .zip

Change History (2)

Changed 9 years ago by Remco Wendt

Attachment: edit_inline_tabular.html added

The mentioned file

comment:1 Changed 9 years ago by Remco Wendt

Resolution: wontfix
Status: newclosed

Closed by moi this will by fixed by newforms-admin, but is here to help others running into the same issue not using newforms-admin

Note: See TracTickets for help on using tickets.
Back to Top