Ticket #8903: 10638.diff

File 10638.diff, 1.8 KB (added by dgouldin, 6 years ago)
  • django/contrib/admin/helpers.py

     
    145145        for name, options in self.fieldsets:
    146146            yield InlineFieldset(self.formset, self.form, name, **options)
    147147
     148    def has_auto_field(self):
     149        return self.form._meta.model._meta.has_auto_field
     150
    148151    def field_count(self):
    149152        # tabular.html uses this function for colspan value.
    150         num_of_fields = 1 # always has at least one field
     153        num_of_fields = 0
     154        if self.has_auto_field():
     155            num_of_fields += 1 # account for auto field
    151156        num_of_fields += len(self.fieldsets[0][1]["fields"])
    152157        if self.formset.can_order:
    153158            num_of_fields += 1
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

     
    2626          {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
    2727          {% 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 %}
    2828            </p>{% endif %}
    29           {{ inline_admin_form.pk_field.field }} {{ inline_admin_form.fk_field.field }}
     29          {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
     30          {{ inline_admin_form.fk_field.field }}
    3031          {% spaceless %}
    3132          {% for fieldset in inline_admin_form %}
    3233            {% for line in fieldset %}
Back to Top