Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #8903 -- Corrected rendering of admin inline formsets (tabular …

…and stacked) when the inline model has a custom non-autofield primary key. Thanks to dgouldin for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10666 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2c24bba934d26ee79f41961859c70935bfc4cd83 1 parent cb5e8e2
@freakboy3742 freakboy3742 authored
View
7 django/contrib/admin/helpers.py
@@ -145,9 +145,14 @@ def __iter__(self):
for name, options in self.fieldsets:
yield InlineFieldset(self.formset, self.form, name, **options)
+ def has_auto_field(self):
+ return self.form._meta.model._meta.has_auto_field
+
def field_count(self):
# tabular.html uses this function for colspan value.
- num_of_fields = 1 # always has at least one field
+ num_of_fields = 0
+ if self.has_auto_field():
+ num_of_fields += 1
num_of_fields += len(self.fieldsets[0][1]["fields"])
if self.formset.can_order:
num_of_fields += 1
View
2  django/contrib/admin/templates/admin/edit_inline/stacked.html
@@ -17,7 +17,7 @@
{% for fieldset in inline_admin_form %}
{% include "admin/includes/fieldset.html" %}
{% endfor %}
- {{ inline_admin_form.pk_field.field }}
+ {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
{{ inline_admin_form.fk_field.field }}
</div>
{% endfor %}
View
17 django/contrib/admin/templates/admin/edit_inline/tabular.html
@@ -14,7 +14,7 @@
{% endfor %}
{% if inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}</th>{% endif %}
</tr></thead>
-
+
{% for inline_admin_form in inline_admin_formset %}
{% if inline_admin_form.form.non_field_errors %}
<tr><td colspan="{{ inline_admin_form.field_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
@@ -26,7 +26,8 @@
{% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
{% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original.content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
</p>{% endif %}
- {{ inline_admin_form.pk_field.field }} {{ inline_admin_form.fk_field.field }}
+ {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
+ {{ inline_admin_form.fk_field.field }}
{% spaceless %}
{% for fieldset in inline_admin_form %}
{% for line in fieldset %}
@@ -48,22 +49,22 @@
{% endfor %}
{% endfor %}
{% endfor %}
-
+
{% if inline_admin_formset.formset.can_delete %}
<td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
{% endif %}
-
+
</tr>
{% endfor %}
-
+
</table>
-
+
</fieldset>
</div>
-
+
{# <ul class="tools"> #}
{# <li><a class="add" href="">Add another {{ inline_admin_formset.opts.verbose_name|title }}</a></li> #}
{# </ul> #}
-
+
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.