1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #33111 -- Fixed passing object to ModelAdmin.get_inlines() when editing in admin change view.

ModelAdmin.get_inlines() should get an unmutated object when creating
formsets during POST request.
This commit is contained in:
Hasan Ramezani
2021-09-16 10:34:10 +02:00
committed by Mariusz Felisiak
parent 1bb8200f2f
commit 2f0f30f973
4 changed files with 43 additions and 5 deletions

View File

@@ -12,8 +12,8 @@ from .models import (
ChildModel1, ChildModel2, Fashionista, FootNote, Holder, Holder2, Holder3,
Holder4, Inner, Inner2, Inner3, Inner4Stacked, Inner4Tabular, Novel,
OutfitItem, Parent, ParentModelWithCustomPk, Person, Poll, Profile,
ProfileCollection, Question, Sighting, SomeChildModel, SomeParentModel,
Teacher, VerboseNamePluralProfile, VerboseNameProfile,
ProfileCollection, Question, ShowInlineParent, Sighting, SomeChildModel,
SomeParentModel, Teacher, VerboseNamePluralProfile, VerboseNameProfile,
)
INLINE_CHANGELINK_HTML = 'class="inlinechangelink">Change</a>'
@@ -618,6 +618,21 @@ class TestInline(TestDataMixin, TestCase):
self.assertContains(response, '<h2>Author</h2>', html=True) # Tabular.
self.assertContains(response, '<h2>Fashionista</h2>', html=True) # Stacked.
def test_inlines_based_on_model_state(self):
parent = ShowInlineParent.objects.create(show_inlines=False)
data = {
'show_inlines': 'on',
'_save': 'Save',
}
change_url = reverse(
'admin:admin_inlines_showinlineparent_change',
args=(parent.id,),
)
response = self.client.post(change_url, data)
self.assertEqual(response.status_code, 302)
parent.refresh_from_db()
self.assertIs(parent.show_inlines, True)
@override_settings(ROOT_URLCONF='admin_inlines.urls')
class TestInlineMedia(TestDataMixin, TestCase):