From 2c24bba934d26ee79f41961859c70935bfc4cd83 Mon Sep 17 00:00:00 2001
From: Russell Keith-Magee
Date: Sun, 3 May 2009 13:37:20 +0000
Subject: [PATCH] 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
---
django/contrib/admin/helpers.py | 7 ++++++-
.../templates/admin/edit_inline/stacked.html | 2 +-
.../templates/admin/edit_inline/tabular.html | 17 +++++++++--------
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
index 9312eab94f..1bd55d70af 100644
--- a/django/contrib/admin/helpers.py
+++ b/django/contrib/admin/helpers.py
@@ -145,9 +145,14 @@ class InlineAdminForm(AdminForm):
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
diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html
index 85488558a2..10629044ed 100644
--- a/django/contrib/admin/templates/admin/edit_inline/stacked.html
+++ b/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 }}
{% endfor %}
diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
index 820928a143..bf947adb76 100644
--- a/django/contrib/admin/templates/admin/edit_inline/tabular.html
+++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html
@@ -14,7 +14,7 @@
{% endfor %}
{% if inline_admin_formset.formset.can_delete %}{% trans "Delete?" %} | {% endif %}
-
+
{% for inline_admin_form in inline_admin_formset %}
{% if inline_admin_form.form.non_field_errors %}
{{ inline_admin_form.form.non_field_errors }} |
@@ -26,7 +26,8 @@
{% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
{% if inline_admin_form.show_url %}{% trans "View on site" %}{% endif %}
{% 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 %}
{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %} |
{% endif %}
-
+
{% endfor %}
-
+
-
+
-
+
{# #}
-
+