Permalink
Browse files

Fixed #29414 -- Restored form inputs on admin inlines when the user d…

…oesn't have the change permission.

Regression in 825f0be.
  • Loading branch information...
czpython authored and timgraham committed May 18, 2018
1 parent a7bc1ae commit ffb72a95bcd6fc5cce7915f3b3732a05837f29a2
Showing with 35 additions and 6 deletions.
  1. +4 −3 django/contrib/admin/helpers.py
  2. +15 −3 tests/admin_inlines/admin.py
  3. +6 −0 tests/admin_inlines/models.py
  4. +10 −0 tests/admin_inlines/tests.py
@@ -244,9 +244,10 @@ def __init__(self, inline, formset, fieldsets, prepopulated_fields=None,
self.has_view_permission = has_view_permission
def __iter__(self):
- readonly_fields_for_editing = self.readonly_fields
- if not self.has_change_permission:
- readonly_fields_for_editing += flatten_fieldsets(self.fieldsets)
+ if self.has_change_permission:
+ readonly_fields_for_editing = self.readonly_fields
+ else:
+ readonly_fields_for_editing = self.readonly_fields + flatten_fieldsets(self.fieldsets)
for form, original in zip(self.formset.initial_forms, self.formset.get_queryset()):
view_on_site_url = self.opts.get_view_on_site_url(original)
@@ -7,9 +7,9 @@
Consigliere, EditablePKBook, ExtraTerrestrial, Fashionista, Holder,
Holder2, Holder3, Holder4, Inner, Inner2, Inner3, Inner4Stacked,
Inner4Tabular, NonAutoPKBook, NonAutoPKBookChild, Novel,
- ParentModelWithCustomPk, Poll, Profile, ProfileCollection, Question,
- ReadOnlyInline, ShoppingWeakness, Sighting, SomeChildModel,
- SomeParentModel, SottoCapo, Title, TitleCollection,
+ NovelReadonlyChapter, ParentModelWithCustomPk, Poll, Profile,
+ ProfileCollection, Question, ReadOnlyInline, ShoppingWeakness, Sighting,
+ SomeChildModel, SomeParentModel, SottoCapo, Title, TitleCollection,
)
site = admin.AdminSite(name="admin")
@@ -153,6 +153,17 @@ class NovelAdmin(admin.ModelAdmin):
inlines = [ChapterInline]
+class ReadOnlyChapterInline(admin.TabularInline):
+ model = Chapter
+
+ def has_change_permission(self, request, obj=None):
+ return False
+
+
+class NovelReadonlyChapterAdmin(admin.ModelAdmin):
+ inlines = [ReadOnlyChapterInline]
+
+
class ConsigliereInline(admin.TabularInline):
model = Consigliere
@@ -231,6 +242,7 @@ class SomeChildModelInline(admin.TabularInline):
site.register(Poll, PollAdmin)
site.register(Novel, NovelAdmin)
+site.register(NovelReadonlyChapter, NovelReadonlyChapterAdmin)
site.register(Fashionista, inlines=[InlineWeakness])
site.register(Holder4, Holder4Admin)
site.register(Author, AuthorAdmin)
@@ -159,6 +159,12 @@ class Novel(models.Model):
name = models.CharField(max_length=40)
+class NovelReadonlyChapter(Novel):
+
+ class Meta:
+ proxy = True
+
+
class Chapter(models.Model):
name = models.CharField(max_length=40)
novel = models.ForeignKey(Novel, models.CASCADE)
@@ -447,6 +447,16 @@ def test_tabular_inline_show_change_link_false_registered(self):
self.assertTrue(response.context['inline_admin_formset'].opts.has_registered_model)
self.assertNotContains(response, INLINE_CHANGELINK_HTML)
+ def test_noneditable_inline_has_field_inputs(self):
+ """Inlines without change permission shows field inputs on add form."""
+ response = self.client.get(reverse('admin:admin_inlines_novelreadonlychapter_add'))
+ self.assertContains(
+ response,
+ '<input type="text" name="chapter_set-0-name" '
+ 'class="vTextField" maxlength="40" id="id_chapter_set-0-name">',
+ html=True
+ )
+
@override_settings(ROOT_URLCONF='admin_inlines.urls')
class TestInlineMedia(TestDataMixin, TestCase):

0 comments on commit ffb72a9

Please sign in to comment.