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
This commit is contained in:
parent
cb5e8e29f0
commit
2c24bba934
|
@ -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
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue