Code

Ticket #12707: 12707.diff

File 12707.diff, 1.9 KB (added by copelco, 4 years ago)
Line 
1diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
2index 00174bc..b110596 100644
3--- a/django/contrib/admin/options.py
4+++ b/django/contrib/admin/options.py
5@@ -698,6 +698,11 @@ class ModelAdmin(BaseModelAdmin):
6         changelist; it returns an HttpResponse if the action was handled, and
7         None otherwise.
8         """
9+        if 'index' not in request.POST:
10+            # If "Go" was not pushed then we can assume the POST was for
11+            # an inline edit save and we do not need to validate the form.
12+            return None
13+
14         # There can be multiple action forms on the page (at the top
15         # and bottom of the change list, for example). Get the action
16         # whose button was pushed.
17diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
18index 0f6f79d..199b41a 100644
19--- a/tests/regressiontests/admin_views/tests.py
20+++ b/tests/regressiontests/admin_views/tests.py
21@@ -940,6 +940,28 @@ class AdminViewListEditable(TestCase):
22         # 1 select per object = 3 selects
23         self.failUnlessEqual(response.content.count("<select"), 4)
24 
25+    def test_post_messages(self):
26+        # Ticket 12707: Saving inline editable should not show admin
27+        # action warnings
28+        data = {
29+            "form-TOTAL_FORMS": "3",
30+            "form-INITIAL_FORMS": "3",
31+            "form-MAX_NUM_FORMS": "0",
32+
33+            "form-0-gender": "1",
34+            "form-0-id": "1",
35+
36+            "form-1-gender": "2",
37+            "form-1-id": "2",
38+
39+            "form-2-alive": "checked",
40+            "form-2-gender": "1",
41+            "form-2-id": "3",
42+        }
43+        response = self.client.post('/test_admin/admin/admin_views/person/',
44+                                    data, follow=True)
45+        self.assertEqual(len(response.context['messages']), 1)
46+
47     def test_post_submission(self):
48         data = {
49             "form-TOTAL_FORMS": "3",