Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.0.X] 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.

Merge of r10666 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10670 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit aefb07d8654e9b2873ad62d599d53c6f027e94de 1 parent e7555c0
@freakboy3742 freakboy3742 authored
View
17 django/contrib/admin/helpers.py
@@ -132,14 +132,19 @@ def __init__(self, formset, form, fieldsets, prepopulated_fields, original):
self.original.content_type_id = ContentType.objects.get_for_model(original).pk
self.show_url = original and hasattr(original, 'get_absolute_url')
super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields)
-
+
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
@@ -149,7 +154,7 @@ def field_count(self):
def pk_field(self):
return AdminField(self.form, self.formset._pk_field.name, False)
-
+
def fk_field(self):
fk = getattr(self.formset, "fk", None)
if fk:
@@ -169,14 +174,14 @@ class InlineFieldset(Fieldset):
def __init__(self, formset, *args, **kwargs):
self.formset = formset
super(InlineFieldset, self).__init__(*args, **kwargs)
-
+
def __iter__(self):
fk = getattr(self.formset, "fk", None)
for field in self.fields:
if fk and fk.name == field:
continue
yield Fieldline(self.form, field)
-
+
class AdminErrorList(forms.util.ErrorList):
"""
Stores all errors for the form/formsets in an add/change stage view.
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.