Ticket #13696: 13696.diff
File 13696.diff, 5.5 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/admin_inlines/tests.py
4 4 5 5 # local test models 6 6 from models import (Holder, Inner, InnerInline, Holder2, Inner2, Holder3, 7 Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child) 7 Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child, Author2, 8 Book2) 8 9 9 10 10 11 class TestInline(TestCase): … … 102 103 # The right callabe should be used for the inline readonly_fields 103 104 # column cells 104 105 self.assertContains(response, '<p>Callable in QuestionInline</p>') 106 107 def test_inline_ids_for_custom_pks(self): 108 """ 109 Tests if the hidden input fields for inline element ids are rendered 110 if the inline model has a custom and non-editable primary key. 111 Refs #13696 112 """ 113 # create the sample objects 114 author = Author2.objects.create(name='Terry Goodkind') 115 book = Book2.objects.create(title='Faith of the Fallen', author=author) 116 # navigate to the author creation page 117 response = self.client.get('/test_admin/admin/admin_inlines/author2/add/') 118 self.assertEqual(response.status_code, 200) 119 # assure the inline models of book got a hidden field with id and name 120 # the first stacked inline 121 self.assertRegexpMatches(response.content, r'<input .*(name="book2_set-0-id").*') 122 self.assertRegexpMatches(response.content, r'<input .*(id="id_book2_set-0-id").*') 123 # the second tabular inline 124 self.assertRegexpMatches(response.content, r'<input .*(name="book2_set-2-0-id").*') 125 self.assertRegexpMatches(response.content, r'<input .*(id="id_book2_set-2-0-id").*') 126 # navigate to the author admin site for the created author instance 127 response = self.client.get('/test_admin/admin/admin_inlines/author2/%s/' % author.pk) 128 self.assertEqual(response.status_code, 200) 129 # assure the inline models of book got a hidden field with id and name 130 # the first stacked inline 131 self.assertRegexpMatches(response.content, r'<input .*(name="book2_set-0-id").*') 132 self.assertRegexpMatches(response.content, r'<input .*(id="id_book2_set-0-id").*') 133 # the second tabular inline 134 self.assertRegexpMatches(response.content, r'<input .*(name="book2_set-2-0-id").*') 135 self.assertRegexpMatches(response.content, r'<input .*(id="id_book2_set-2-0-id").*') 136 105 137 106 138 class TestInlineMedia(TestCase): 107 139 fixtures = ['admin-views-users.xml'] -
tests/regressiontests/admin_inlines/models.py
191 191 192 192 admin.site.register(Poll, PollAdmin) 193 193 admin.site.register(Novel, NovelAdmin) 194 195 196 # models for #13696 197 class Author2(models.Model): 198 name = models.CharField(max_length=100) 199 200 class Book2(models.Model): 201 id = models.CharField(max_length=32, primary_key=True, editable=False) 202 author = models.ForeignKey(Author2) 203 title = models.CharField(max_length=100) 204 205 def save(self, *args, **kwargs): 206 """ 207 Creates a new random id and assigns it to the primary field. 208 """ 209 if not self.id: 210 import random 211 self.id = str(random.random()) 212 super(Book2, self).save(*args, **kwargs) 213 214 class Book2StackedInline(admin.StackedInline): 215 model = Book2 216 217 class Book2TabularInline(admin.TabularInline): 218 model = Book2 219 220 class Author2Admin(admin.ModelAdmin): 221 inlines = [Book2StackedInline, Book2TabularInline] 222 class Meta: 223 model = Author2 224 225 admin.site.register(Author2, Author2Admin) -
django/contrib/admin/templates/admin/edit_inline/stacked.html
13 13 {% for fieldset in inline_admin_form %} 14 14 {% include "admin/includes/fieldset.html" %} 15 15 {% endfor %} 16 {% if inline_admin_form. has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}16 {% if inline_admin_form.pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %} 17 17 {{ inline_admin_form.fk_field.field }} 18 18 </div>{% endfor %} 19 19 </div> -
django/contrib/admin/templates/admin/edit_inline/tabular.html
27 27 {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %} 28 28 {% 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 %} 29 29 </p>{% endif %} 30 {% if inline_admin_form. has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}30 {% if inline_admin_form.pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %} 31 31 {{ inline_admin_form.fk_field.field }} 32 32 {% spaceless %} 33 33 {% for fieldset in inline_admin_form %}