Code

Ticket #9651: patch1.diff

File patch1.diff, 3.6 KB (added by kmike, 5 years ago)
Line 
1Index: django/forms/models.py
2===================================================================
3--- django/forms/models.py      (revision 9814)
4+++ django/forms/models.py      (working copy)
5@@ -487,6 +487,9 @@
6             # Remove the primary key from the form's data, we are only
7             # creating new instances
8             form.data[form.add_prefix(self._pk_field.name)] = None
9+
10+            # Remove the foreign key from the form's data
11+            form.data[form.add_prefix(self.fk.name)] = None
12         return form
13 
14     def save_new(self, form, commit=True):
15Index: tests/regressiontests/admin_views/tests.py
16===================================================================
17--- tests/regressiontests/admin_views/tests.py  (revision 9814)
18+++ tests/regressiontests/admin_views/tests.py  (working copy)
19@@ -85,35 +85,47 @@
20             "article_set-0-content": u"<p>Middle content</p>",
21             "article_set-0-date_0": u"2008-03-18",
22             "article_set-0-date_1": u"11:54:58",
23+            "article_set-0-section": u"1",
24             "article_set-1-id": u"2",
25             "article_set-1-title": u"Need a title.",
26             "article_set-1-content": u"<p>Oldest content</p>",
27             "article_set-1-date_0": u"2000-03-18",
28             "article_set-1-date_1": u"11:54:58",
29+            "article_set-1-section": u"1",
30             "article_set-2-id": u"3",
31             "article_set-2-title": u"Need a title.",
32             "article_set-2-content": u"<p>Newest content</p>",
33             "article_set-2-date_0": u"2009-03-18",
34             "article_set-2-date_1": u"11:54:58",
35+            "article_set-2-section": u"1",
36             "article_set-3-id": u"",
37             "article_set-3-title": u"",
38             "article_set-3-content": u"",
39             "article_set-3-date_0": u"",
40             "article_set-3-date_1": u"",
41+            "article_set-3-section": u"1",
42             "article_set-4-id": u"",
43             "article_set-4-title": u"",
44             "article_set-4-content": u"",
45             "article_set-4-date_0": u"",
46             "article_set-4-date_1": u"",
47+            "article_set-4-section": u"1",
48             "article_set-5-id": u"",
49             "article_set-5-title": u"",
50             "article_set-5-content": u"",
51             "article_set-5-date_0": u"",
52             "article_set-5-date_1": u"",
53+            "article_set-5-section": u"1",
54         }
55         response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
56         self.failUnlessEqual(response.status_code, 302) # redirect somewhere
57 
58+        # test save_as
59+        post_data.update({'_saveasnew': u'Save+as+new',})
60+        response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
61+        self.failUnlessEqual(response.status_code, 302) # redirect somewhere
62+
63+
64     def testChangeListSortingCallable(self):
65         """
66         Ensure we can sort on a list_display field that is a callable
67Index: tests/regressiontests/admin_views/models.py
68===================================================================
69--- tests/regressiontests/admin_views/models.py (revision 9814)
70+++ tests/regressiontests/admin_views/models.py (working copy)
71@@ -136,7 +136,7 @@
72 
73 admin.site.register(Article, ArticleAdmin)
74 admin.site.register(CustomArticle, CustomArticleAdmin)
75-admin.site.register(Section, inlines=[ArticleInline])
76+admin.site.register(Section, save_as=True, inlines=[ArticleInline])
77 admin.site.register(ModelWithStringPrimaryKey)
78 admin.site.register(Color)
79 admin.site.register(Thing, ThingAdmin)