Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #9651: fixed save_as with inline forms. Thanks, kmike a…

…nd Mnewman.

Backport of r10353 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10612 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7ff22ef258e464b44cbb295738e7c0776ab7909f 1 parent 0d17a5c
Karen Tracey authored April 21, 2009
3  django/forms/models.py
@@ -496,6 +496,9 @@ def _construct_form(self, i, **kwargs):
496 496
             # Remove the primary key from the form's data, we are only
497 497
             # creating new instances
498 498
             form.data[form.add_prefix(self._pk_field.name)] = None
  499
+
  500
+            # Remove the foreign key from the form's data
  501
+            form.data[form.add_prefix(self.fk.name)] = None
499 502
         return form
500 503
 
501 504
     #@classmethod
2  tests/regressiontests/admin_views/models.py
@@ -240,7 +240,7 @@ class PictureAdmin(admin.ModelAdmin):
240 240
 
241 241
 admin.site.register(Article, ArticleAdmin)
242 242
 admin.site.register(CustomArticle, CustomArticleAdmin)
243  
-admin.site.register(Section, inlines=[ArticleInline])
  243
+admin.site.register(Section, save_as=True, inlines=[ArticleInline])
244 244
 admin.site.register(ModelWithStringPrimaryKey)
245 245
 admin.site.register(Color)
246 246
 admin.site.register(Thing, ThingAdmin)
95  tests/regressiontests/admin_views/tests.py
@@ -23,6 +23,7 @@
23 23
 
24 24
 class AdminViewBasicTest(TestCase):
25 25
     fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml']
  26
+    urlbit = 'admin'
26 27
 
27 28
     def setUp(self):
28 29
         self.client.login(username='super', password='secret')
@@ -74,48 +75,66 @@ def testBasicAddPost(self):
74 75
         response = self.client.post('/test_admin/admin/admin_views/section/add/', post_data)
75 76
         self.failUnlessEqual(response.status_code, 302) # redirect somewhere
76 77
 
  78
+    # Post data for edit inline
  79
+    inline_post_data = {
  80
+        "name": u"Test section",
  81
+        # inline data
  82
+        "article_set-TOTAL_FORMS": u"6",
  83
+        "article_set-INITIAL_FORMS": u"3",
  84
+        "article_set-0-id": u"1",
  85
+        # there is no title in database, give one here or formset will fail.
  86
+        "article_set-0-title": u"Norske bostaver æøå skaper problemer",
  87
+        "article_set-0-content": u"<p>Middle content</p>",
  88
+        "article_set-0-date_0": u"2008-03-18",
  89
+        "article_set-0-date_1": u"11:54:58",
  90
+        "article_set-0-section": u"1",
  91
+        "article_set-1-id": u"2",
  92
+        "article_set-1-title": u"Need a title.",
  93
+        "article_set-1-content": u"<p>Oldest content</p>",
  94
+        "article_set-1-date_0": u"2000-03-18",
  95
+        "article_set-1-date_1": u"11:54:58",
  96
+        "article_set-2-id": u"3",
  97
+        "article_set-2-title": u"Need a title.",
  98
+        "article_set-2-content": u"<p>Newest content</p>",
  99
+        "article_set-2-date_0": u"2009-03-18",
  100
+        "article_set-2-date_1": u"11:54:58",
  101
+        "article_set-3-id": u"",
  102
+        "article_set-3-title": u"",
  103
+        "article_set-3-content": u"",
  104
+        "article_set-3-date_0": u"",
  105
+        "article_set-3-date_1": u"",
  106
+        "article_set-4-id": u"",
  107
+        "article_set-4-title": u"",
  108
+        "article_set-4-content": u"",
  109
+        "article_set-4-date_0": u"",
  110
+        "article_set-4-date_1": u"",
  111
+        "article_set-5-id": u"",
  112
+        "article_set-5-title": u"",
  113
+        "article_set-5-content": u"",
  114
+        "article_set-5-date_0": u"",
  115
+        "article_set-5-date_1": u"",
  116
+    }
  117
+
77 118
     def testBasicEditPost(self):
78 119
         """
79 120
         A smoke test to ensure POST on edit_view works.
80 121
         """
81  
-        post_data = {
82  
-            "name": u"Test section",
83  
-            # inline data
84  
-            "article_set-TOTAL_FORMS": u"6",
85  
-            "article_set-INITIAL_FORMS": u"3",
86  
-            "article_set-0-id": u"1",
87  
-            # there is no title in database, give one here or formset
88  
-            # 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-1-id": u"2",
94  
-            "article_set-1-title": u"Need a title.",
95  
-            "article_set-1-content": u"<p>Oldest content</p>",
96  
-            "article_set-1-date_0": u"2000-03-18",
97  
-            "article_set-1-date_1": u"11:54:58",
98  
-            "article_set-2-id": u"3",
99  
-            "article_set-2-title": u"Need a title.",
100  
-            "article_set-2-content": u"<p>Newest content</p>",
101  
-            "article_set-2-date_0": u"2009-03-18",
102  
-            "article_set-2-date_1": u"11:54:58",
103  
-            "article_set-3-id": u"",
104  
-            "article_set-3-title": u"",
105  
-            "article_set-3-content": u"",
106  
-            "article_set-3-date_0": u"",
107  
-            "article_set-3-date_1": u"",
108  
-            "article_set-4-id": u"",
109  
-            "article_set-4-title": u"",
110  
-            "article_set-4-content": u"",
111  
-            "article_set-4-date_0": u"",
112  
-            "article_set-4-date_1": u"",
113  
-            "article_set-5-id": u"",
114  
-            "article_set-5-title": u"",
115  
-            "article_set-5-content": u"",
116  
-            "article_set-5-date_0": u"",
117  
-            "article_set-5-date_1": u"",
118  
-        }
  122
+        response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, self.inline_post_data)
  123
+        self.failUnlessEqual(response.status_code, 302) # redirect somewhere
  124
+
  125
+    def testEditSaveAs(self):
  126
+        """
  127
+        Test "save as".
  128
+        """
  129
+        post_data = self.inline_post_data.copy()
  130
+        post_data.update({
  131
+            '_saveasnew': u'Save+as+new',
  132
+            "article_set-1-section": u"1",
  133
+            "article_set-2-section": u"1",
  134
+            "article_set-3-section": u"1",
  135
+            "article_set-4-section": u"1",
  136
+            "article_set-5-section": u"1",
  137
+        })
119 138
         response = self.client.post('/test_admin/admin/admin_views/section/1/', post_data)
120 139
         self.failUnlessEqual(response.status_code, 302) # redirect somewhere
121 140
 

0 notes on commit 7ff22ef

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