Ticket #18263: 18263.diff

File 18263.diff, 4.6 KB (added by Harro, 12 years ago)

Added regression test

  • django/contrib/admin/templates/admin/edit_inline/tabular.html

    diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
    index d5ac9b0..760bae7 100644
    a b  
    3535          {% for fieldset in inline_admin_form %}
    3636            {% for line in fieldset %}
    3737              {% for field in line %}
    38                 {% if field.is_hidden %} {{ field.field }} {% endif %}
     38                {% if field.field.is_hidden %} {{ field.field }} {% endif %}
    3939              {% endfor %}
    4040            {% endfor %}
    4141          {% endfor %}
     
    4444        {% for fieldset in inline_admin_form %}
    4545          {% for line in fieldset %}
    4646            {% for field in line %}
     47              {% if not field.field.is_hidden %}
    4748              <td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
    4849              {% if field.is_readonly %}
    4950                  <p>{{ field.contents }}</p>
     
    5253                  {{ field.field }}
    5354              {% endif %}
    5455              </td>
     56              {% endif %}
    5557            {% endfor %}
    5658          {% endfor %}
    5759        {% endfor %}
  • tests/regressiontests/admin_inlines/admin.py

    diff --git a/tests/regressiontests/admin_inlines/admin.py b/tests/regressiontests/admin_inlines/admin.py
    index cf51fa4..6b51ad2 100644
    a b class ChildModel2Inline(admin.StackedInline):  
    125125    model = ChildModel2
    126126
    127127
     128#admin and form for #18263
     129class SomeChildModelForm(forms.ModelForm):
     130
     131    class Meta:
     132        model = SomeChildModel
     133        widgets = {
     134            'position': forms.HiddenInput,
     135        }
     136
     137
     138class SomeChildModelInline(admin.TabularInline):
     139    model = SomeChildModel
     140    form = SomeChildModelForm
     141
     142
    128143site.register(TitleCollection, inlines=[TitleInline])
    129144# Test bug #12561 and #12778
    130145# only ModelAdmin media
    site.register(Holder4, Holder4Admin)  
    141156site.register(Author, AuthorAdmin)
    142157site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline])
    143158site.register(ProfileCollection, inlines=[ProfileInline])
    144 site.register(ParentModelWithCustomPk, inlines=[ChildModel1Inline, ChildModel2Inline])
    145  No newline at end of file
     159site.register(ParentModelWithCustomPk, inlines=[ChildModel1Inline, ChildModel2Inline])
     160site.register(SomeParentModel, inlines=[SomeChildModelInline])
  • tests/regressiontests/admin_inlines/models.py

    diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py
    index 5a0f4d8..6cafa3b 100644
    a b class ChildModel2(models.Model):  
    164164        return '/child_model2/'
    165165
    166166
     167# Models for #18263
     168
     169class SomeParentModel(models.Model):
     170    name = models.CharField(max_length=1)
     171
     172
     173class SomeChildModel(models.Model):
     174    name = models.CharField(max_length=1)
     175    position = models.PositiveIntegerField()
     176    parent = models.ForeignKey(SomeParentModel)
     177
    167178# Other models
    168179
    169180class ProfileCollection(models.Model):
  • tests/regressiontests/admin_inlines/tests.py

    diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py
    index 4f25d3d..f904479 100644
    a b from django.test.utils import override_settings  
    1111from .admin import InnerInline
    1212from .models import (Holder, Inner, Holder2, Inner2, Holder3, Inner3, Person,
    1313    OutfitItem, Fashionista, Teacher, Parent, Child, Author, Book, Profile,
    14     ProfileCollection, ParentModelWithCustomPk, ChildModel1, ChildModel2)
     14    ProfileCollection, ParentModelWithCustomPk, ChildModel1, ChildModel2,
     15    SomeParentModel, SomeChildModel)
    1516
    1617
    1718@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
    class TestInline(TestCase):  
    161162        self.assertContains(response, child1_shortcut)
    162163        self.assertContains(response, child2_shortcut)
    163164
     165    def test_inline_hidden_field_no_column(self):
     166        """Make sure hidden fields don't get a column in tabular inlines"""
     167        parent = SomeParentModel.objects.create(name='a')
     168        SomeChildModel.objects.create(name='b', position='0', parent=parent)
     169        SomeChildModel.objects.create(name='c', position='1', parent=parent)
     170        response = self.client.get('/admin/admin_inlines/someparentmodel/%s/' % parent.pk)
     171        self.assertNotContains(response, '<td class="field-position">')
     172
    164173
    165174@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
    166175class TestInlineMedia(TestCase):
Back to Top