Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18263 -- Corrrected handling of hidden fields in tabular admin…

… inlines.

Thanks hvdklauw for the report and patch.
  • Loading branch information...
commit 617aceb1b4ec97b4d70f9b3071cb46a645f69f87 1 parent 4dbd95a
Tim Graham timgraham authored
4 django/contrib/admin/templates/admin/edit_inline/tabular.html
View
@@ -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 %}
<td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
{% if field.is_readonly %}
<p>{{ field.contents|linebreaksbr }}</p>
@@ -52,6 +53,7 @@
{{ field.field }}
{% endif %}
</td>
+ {% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
17 tests/admin_inlines/admin.py
View
@@ -165,6 +165,22 @@ def get_max_num(self, request, obj=None, **kwargs):
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 @@ class SightingInline(admin.TabularInline):
site.register(ParentModelWithCustomPk, inlines=[ChildModel1Inline, ChildModel2Inline])
site.register(BinaryTree, inlines=[BinaryTreeAdmin])
site.register(ExtraTerrestrial, inlines=[SightingInline])
+site.register(SomeParentModel, inlines=[SomeChildModelInline])
11 tests/admin_inlines/models.py
View
@@ -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):
13 tests/admin_inlines/tests.py
View
@@ -12,7 +12,8 @@
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 @@ def test_help_text(self):
response = self.client.get('/admin/admin_inlines/capofamiglia/add/')
self.assertContains(response, '<img src="/static/admin/img/icon-unknown.gif" class="help help-tooltip" width="10" height="10" alt="(Help text for ReadOnlyInline)" title="Help text for ReadOnlyInline" />', 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, '<td class="field-position">')
+ self.assertContains(response, (
+ '<input id="id_somechildmodel_set-1-position" '
+ 'name="somechildmodel_set-1-position" type="hidden" value="1" />'))
def test_non_related_name_inline(self):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.