diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
index e6097f0dce..0bfa405272 100644
--- a/django/contrib/admin/templates/admin/edit_inline/tabular.html
+++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html
@@ -35,7 +35,7 @@
{% for fieldset in inline_admin_form %}
{% for line in fieldset %}
{% for field in line %}
- {% if field.is_hidden %} {{ field.field }} {% endif %}
+ {% if field.field.is_hidden %} {{ field.field }} {% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
@@ -44,6 +44,7 @@
{% for fieldset in inline_admin_form %}
{% for line in fieldset %}
{% for field in line %}
+ {% if not field.field.is_hidden %}
{% if field.is_readonly %}
{{ field.contents|linebreaksbr }}
@@ -52,6 +53,7 @@
{{ field.field }}
{% endif %}
+ {% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
diff --git a/tests/admin_inlines/admin.py b/tests/admin_inlines/admin.py
index c69800851a..c141abe54e 100644
--- a/tests/admin_inlines/admin.py
+++ b/tests/admin_inlines/admin.py
@@ -165,6 +165,22 @@ class BinaryTreeAdmin(admin.TabularInline):
class SightingInline(admin.TabularInline):
model = Sighting
+# admin and form for #18263
+class SomeChildModelForm(forms.ModelForm):
+
+ class Meta:
+ fields = '__all__'
+ model = SomeChildModel
+ widgets = {
+ 'position': forms.HiddenInput,
+ }
+
+
+class SomeChildModelInline(admin.TabularInline):
+ model = SomeChildModel
+ form = SomeChildModelForm
+
+
site.register(TitleCollection, inlines=[TitleInline])
# Test bug #12561 and #12778
# only ModelAdmin media
@@ -184,3 +200,4 @@ site.register(ProfileCollection, inlines=[ProfileInline])
site.register(ParentModelWithCustomPk, inlines=[ChildModel1Inline, ChildModel2Inline])
site.register(BinaryTree, inlines=[BinaryTreeAdmin])
site.register(ExtraTerrestrial, inlines=[SightingInline])
+site.register(SomeParentModel, inlines=[SomeChildModelInline])
diff --git a/tests/admin_inlines/models.py b/tests/admin_inlines/models.py
index dde5cf79e3..36e9e8e54d 100644
--- a/tests/admin_inlines/models.py
+++ b/tests/admin_inlines/models.py
@@ -221,6 +221,17 @@ class Sighting(models.Model):
et = models.ForeignKey(ExtraTerrestrial)
place = models.CharField(max_length=100)
+
+# Models for #18263
+class SomeParentModel(models.Model):
+ name = models.CharField(max_length=1)
+
+
+class SomeChildModel(models.Model):
+ name = models.CharField(max_length=1)
+ position = models.PositiveIntegerField()
+ parent = models.ForeignKey(SomeParentModel)
+
# Other models
class ProfileCollection(models.Model):
diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py
index b7765b7f86..871852425a 100644
--- a/tests/admin_inlines/tests.py
+++ b/tests/admin_inlines/tests.py
@@ -12,7 +12,8 @@ from .admin import InnerInline
from .models import (Holder, Inner, Holder2, Inner2, Holder3, Inner3, Person,
OutfitItem, Fashionista, Teacher, Parent, Child, Author, Book, Profile,
ProfileCollection, ParentModelWithCustomPk, ChildModel1, ChildModel2,
- Sighting, Novel, Chapter, FootNote, BinaryTree)
+ Sighting, Novel, Chapter, FootNote, BinaryTree, SomeParentModel,
+ SomeChildModel)
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
@@ -126,6 +127,16 @@ class TestInline(TestCase):
response = self.client.get('/admin/admin_inlines/capofamiglia/add/')
self.assertContains(response, '', 1)
+ def test_inline_hidden_field_no_column(self):
+ """#18263 -- Make sure hidden fields don't get a column in tabular inlines"""
+ parent = SomeParentModel.objects.create(name='a')
+ SomeChildModel.objects.create(name='b', position='0', parent=parent)
+ SomeChildModel.objects.create(name='c', position='1', parent=parent)
+ response = self.client.get('/admin/admin_inlines/someparentmodel/%s/' % parent.pk)
+ self.assertNotContains(response, '