mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
64e82fb648
commit
8f7aa84def
|
@ -530,6 +530,9 @@ class BaseInlineFormSet(BaseModelFormSet):
|
||||||
# Remove the primary key from the form's data, we are only
|
# Remove the primary key from the form's data, we are only
|
||||||
# creating new instances
|
# creating new instances
|
||||||
form.data[form.add_prefix(self._pk_field.name)] = None
|
form.data[form.add_prefix(self._pk_field.name)] = None
|
||||||
|
|
||||||
|
# Remove the foreign key from the form's data
|
||||||
|
form.data[form.add_prefix(self.fk.name)] = None
|
||||||
return form
|
return form
|
||||||
|
|
||||||
#@classmethod
|
#@classmethod
|
||||||
|
|
|
@ -287,7 +287,7 @@ class EmptyModelAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
admin.site.register(Article, ArticleAdmin)
|
admin.site.register(Article, ArticleAdmin)
|
||||||
admin.site.register(CustomArticle, CustomArticleAdmin)
|
admin.site.register(CustomArticle, CustomArticleAdmin)
|
||||||
admin.site.register(Section, inlines=[ArticleInline])
|
admin.site.register(Section, save_as=True, inlines=[ArticleInline])
|
||||||
admin.site.register(ModelWithStringPrimaryKey)
|
admin.site.register(ModelWithStringPrimaryKey)
|
||||||
admin.site.register(Color)
|
admin.site.register(Color)
|
||||||
admin.site.register(Thing, ThingAdmin)
|
admin.site.register(Thing, ThingAdmin)
|
||||||
|
|
|
@ -78,48 +78,66 @@ class AdminViewBasicTest(TestCase):
|
||||||
response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data)
|
response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data)
|
||||||
self.failUnlessEqual(response.status_code, 302) # redirect somewhere
|
self.failUnlessEqual(response.status_code, 302) # redirect somewhere
|
||||||
|
|
||||||
|
# Post data for edit inline
|
||||||
|
inline_post_data = {
|
||||||
|
"name": u"Test section",
|
||||||
|
# inline data
|
||||||
|
"article_set-TOTAL_FORMS": u"6",
|
||||||
|
"article_set-INITIAL_FORMS": u"3",
|
||||||
|
"article_set-0-id": u"1",
|
||||||
|
# there is no title in database, give one here or formset will fail.
|
||||||
|
"article_set-0-title": u"Norske bostaver æøå skaper problemer",
|
||||||
|
"article_set-0-content": u"<p>Middle content</p>",
|
||||||
|
"article_set-0-date_0": u"2008-03-18",
|
||||||
|
"article_set-0-date_1": u"11:54:58",
|
||||||
|
"article_set-0-section": u"1",
|
||||||
|
"article_set-1-id": u"2",
|
||||||
|
"article_set-1-title": u"Need a title.",
|
||||||
|
"article_set-1-content": u"<p>Oldest content</p>",
|
||||||
|
"article_set-1-date_0": u"2000-03-18",
|
||||||
|
"article_set-1-date_1": u"11:54:58",
|
||||||
|
"article_set-2-id": u"3",
|
||||||
|
"article_set-2-title": u"Need a title.",
|
||||||
|
"article_set-2-content": u"<p>Newest content</p>",
|
||||||
|
"article_set-2-date_0": u"2009-03-18",
|
||||||
|
"article_set-2-date_1": u"11:54:58",
|
||||||
|
"article_set-3-id": u"",
|
||||||
|
"article_set-3-title": u"",
|
||||||
|
"article_set-3-content": u"",
|
||||||
|
"article_set-3-date_0": u"",
|
||||||
|
"article_set-3-date_1": u"",
|
||||||
|
"article_set-4-id": u"",
|
||||||
|
"article_set-4-title": u"",
|
||||||
|
"article_set-4-content": u"",
|
||||||
|
"article_set-4-date_0": u"",
|
||||||
|
"article_set-4-date_1": u"",
|
||||||
|
"article_set-5-id": u"",
|
||||||
|
"article_set-5-title": u"",
|
||||||
|
"article_set-5-content": u"",
|
||||||
|
"article_set-5-date_0": u"",
|
||||||
|
"article_set-5-date_1": u"",
|
||||||
|
}
|
||||||
|
|
||||||
def testBasicEditPost(self):
|
def testBasicEditPost(self):
|
||||||
"""
|
"""
|
||||||
A smoke test to ensure POST on edit_view works.
|
A smoke test to ensure POST on edit_view works.
|
||||||
"""
|
"""
|
||||||
post_data = {
|
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, self.inline_post_data)
|
||||||
"name": u"Test section",
|
self.failUnlessEqual(response.status_code, 302) # redirect somewhere
|
||||||
# inline data
|
|
||||||
"article_set-TOTAL_FORMS": u"6",
|
def testEditSaveAs(self):
|
||||||
"article_set-INITIAL_FORMS": u"3",
|
"""
|
||||||
"article_set-0-id": u"1",
|
Test "save as".
|
||||||
# there is no title in database, give one here or formset
|
"""
|
||||||
# will fail.
|
post_data = self.inline_post_data.copy()
|
||||||
"article_set-0-title": u"Norske bostaver æøå skaper problemer",
|
post_data.update({
|
||||||
"article_set-0-content": u"<p>Middle content</p>",
|
'_saveasnew': u'Save+as+new',
|
||||||
"article_set-0-date_0": u"2008-03-18",
|
"article_set-1-section": u"1",
|
||||||
"article_set-0-date_1": u"11:54:58",
|
"article_set-2-section": u"1",
|
||||||
"article_set-1-id": u"2",
|
"article_set-3-section": u"1",
|
||||||
"article_set-1-title": u"Need a title.",
|
"article_set-4-section": u"1",
|
||||||
"article_set-1-content": u"<p>Oldest content</p>",
|
"article_set-5-section": u"1",
|
||||||
"article_set-1-date_0": u"2000-03-18",
|
})
|
||||||
"article_set-1-date_1": u"11:54:58",
|
|
||||||
"article_set-2-id": u"3",
|
|
||||||
"article_set-2-title": u"Need a title.",
|
|
||||||
"article_set-2-content": u"<p>Newest content</p>",
|
|
||||||
"article_set-2-date_0": u"2009-03-18",
|
|
||||||
"article_set-2-date_1": u"11:54:58",
|
|
||||||
"article_set-3-id": u"",
|
|
||||||
"article_set-3-title": u"",
|
|
||||||
"article_set-3-content": u"",
|
|
||||||
"article_set-3-date_0": u"",
|
|
||||||
"article_set-3-date_1": u"",
|
|
||||||
"article_set-4-id": u"",
|
|
||||||
"article_set-4-title": u"",
|
|
||||||
"article_set-4-content": u"",
|
|
||||||
"article_set-4-date_0": u"",
|
|
||||||
"article_set-4-date_1": u"",
|
|
||||||
"article_set-5-id": u"",
|
|
||||||
"article_set-5-title": u"",
|
|
||||||
"article_set-5-content": u"",
|
|
||||||
"article_set-5-date_0": u"",
|
|
||||||
"article_set-5-date_1": u"",
|
|
||||||
}
|
|
||||||
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
|
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
|
||||||
self.failUnlessEqual(response.status_code, 302) # redirect somewhere
|
self.failUnlessEqual(response.status_code, 302) # redirect somewhere
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue