Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9651: fixed save_as with inline forms. Thanks, kmike and Mnewman.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10353 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8f7aa84def3c13dd706aae1f5bfbcdb54b0696ee 1 parent 64e82fb
Jacob Kaplan-Moss authored
3  django/forms/models.py
@@ -530,6 +530,9 @@ def _construct_form(self, i, **kwargs):
530 530
             # Remove the primary key from the form's data, we are only
531 531
             # creating new instances
532 532
             form.data[form.add_prefix(self._pk_field.name)] = None
  533
+
  534
+            # Remove the foreign key from the form's data
  535
+            form.data[form.add_prefix(self.fk.name)] = None
533 536
         return form
534 537
 
535 538
     #@classmethod
2  tests/regressiontests/admin_views/models.py
@@ -287,7 +287,7 @@ def queryset(self, request):
287 287
 
288 288
 admin.site.register(Article, ArticleAdmin)
289 289
 admin.site.register(CustomArticle, CustomArticleAdmin)
290  
-admin.site.register(Section, inlines=[ArticleInline])
  290
+admin.site.register(Section, save_as=True, inlines=[ArticleInline])
291 291
 admin.site.register(ModelWithStringPrimaryKey)
292 292
 admin.site.register(Color)
293 293
 admin.site.register(Thing, ThingAdmin)
94  tests/regressiontests/admin_views/tests.py
@@ -78,48 +78,66 @@ def testBasicAddPost(self):
78 78
         response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data)
79 79
         self.failUnlessEqual(response.status_code, 302) # redirect somewhere
80 80
 
  81
+    # Post data for edit inline
  82
+    inline_post_data = {
  83
+        "name": u"Test section",
  84
+        # inline data
  85
+        "article_set-TOTAL_FORMS": u"6",
  86
+        "article_set-INITIAL_FORMS": u"3",
  87
+        "article_set-0-id": u"1",
  88
+        # there is no title in database, give one here or formset will fail.
  89
+        "article_set-0-title": u"Norske bostaver æøå skaper problemer",
  90
+        "article_set-0-content": u"<p>Middle content</p>",
  91
+        "article_set-0-date_0": u"2008-03-18",
  92
+        "article_set-0-date_1": u"11:54:58",
  93
+        "article_set-0-section": u"1",
  94
+        "article_set-1-id": u"2",
  95
+        "article_set-1-title": u"Need a title.",
  96
+        "article_set-1-content": u"<p>Oldest content</p>",
  97
+        "article_set-1-date_0": u"2000-03-18",
  98
+        "article_set-1-date_1": u"11:54:58",
  99
+        "article_set-2-id": u"3",
  100
+        "article_set-2-title": u"Need a title.",
  101
+        "article_set-2-content": u"<p>Newest content</p>",
  102
+        "article_set-2-date_0": u"2009-03-18",
  103
+        "article_set-2-date_1": u"11:54:58",
  104
+        "article_set-3-id": u"",
  105
+        "article_set-3-title": u"",
  106
+        "article_set-3-content": u"",
  107
+        "article_set-3-date_0": u"",
  108
+        "article_set-3-date_1": u"",
  109
+        "article_set-4-id": u"",
  110
+        "article_set-4-title": u"",
  111
+        "article_set-4-content": u"",
  112
+        "article_set-4-date_0": u"",
  113
+        "article_set-4-date_1": u"",
  114
+        "article_set-5-id": u"",
  115
+        "article_set-5-title": u"",
  116
+        "article_set-5-content": u"",
  117
+        "article_set-5-date_0": u"",
  118
+        "article_set-5-date_1": u"",
  119
+    }
  120
+
81 121
     def testBasicEditPost(self):
82 122
         """
83 123
         A smoke test to ensure POST on edit_view works.
84 124
         """
85  
-        post_data = {
86  
-            "name": u"Test section",
87  
-            # inline data
88  
-            "article_set-TOTAL_FORMS": u"6",
89  
-            "article_set-INITIAL_FORMS": u"3",
90  
-            "article_set-0-id": u"1",
91  
-            # there is no title in database, give one here or formset
92  
-            # will fail.
93  
-            "article_set-0-title": u"Norske bostaver æøå skaper problemer",
94  
-            "article_set-0-content": u"<p>Middle content</p>",
95  
-            "article_set-0-date_0": u"2008-03-18",
96  
-            "article_set-0-date_1": u"11:54:58",
97  
-            "article_set-1-id": u"2",
98  
-            "article_set-1-title": u"Need a title.",
99  
-            "article_set-1-content": u"<p>Oldest content</p>",
100  
-            "article_set-1-date_0": u"2000-03-18",
101  
-            "article_set-1-date_1": u"11:54:58",
102  
-            "article_set-2-id": u"3",
103  
-            "article_set-2-title": u"Need a title.",
104  
-            "article_set-2-content": u"<p>Newest content</p>",
105  
-            "article_set-2-date_0": u"2009-03-18",
106  
-            "article_set-2-date_1": u"11:54:58",
107  
-            "article_set-3-id": u"",
108  
-            "article_set-3-title": u"",
109  
-            "article_set-3-content": u"",
110  
-            "article_set-3-date_0": u"",
111  
-            "article_set-3-date_1": u"",
112  
-            "article_set-4-id": u"",
113  
-            "article_set-4-title": u"",
114  
-            "article_set-4-content": u"",
115  
-            "article_set-4-date_0": u"",
116  
-            "article_set-4-date_1": u"",
117  
-            "article_set-5-id": u"",
118  
-            "article_set-5-title": u"",
119  
-            "article_set-5-content": u"",
120  
-            "article_set-5-date_0": u"",
121  
-            "article_set-5-date_1": u"",
122  
-        }
  125
+        response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, self.inline_post_data)
  126
+        self.failUnlessEqual(response.status_code, 302) # redirect somewhere
  127
+
  128
+    def testEditSaveAs(self):
  129
+        """
  130
+        Test "save as".
  131
+        """
  132
+        post_data = self.inline_post_data.copy()
  133
+        post_data.update({
  134
+            '_saveasnew': u'Save+as+new',
  135
+            "article_set-1-section": u"1",
  136
+            "article_set-2-section": u"1",
  137
+            "article_set-3-section": u"1",
  138
+            "article_set-4-section": u"1",
  139
+            "article_set-5-section": u"1",
  140
+        })
123 141
         response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
124 142
         self.failUnlessEqual(response.status_code, 302) # redirect somewhere
125 143
 

0 notes on commit 8f7aa84

Please sign in to comment.
Something went wrong with that request. Please try again.