Ticket #9651: patch1.diff

File patch1.diff, 3.6 KB (added by kmike, 6 years ago)
  • django/forms/models.py

     
    487487            # Remove the primary key from the form's data, we are only
    488488            # creating new instances
    489489            form.data[form.add_prefix(self._pk_field.name)] = None
     490
     491            # Remove the foreign key from the form's data
     492            form.data[form.add_prefix(self.fk.name)] = None
    490493        return form
    491494
    492495    def save_new(self, form, commit=True):
  • tests/regressiontests/admin_views/tests.py

     
    8585            "article_set-0-content": u"<p>Middle content</p>",
    8686            "article_set-0-date_0": u"2008-03-18",
    8787            "article_set-0-date_1": u"11:54:58",
     88            "article_set-0-section": u"1",
    8889            "article_set-1-id": u"2",
    8990            "article_set-1-title": u"Need a title.",
    9091            "article_set-1-content": u"<p>Oldest content</p>",
    9192            "article_set-1-date_0": u"2000-03-18",
    9293            "article_set-1-date_1": u"11:54:58",
     94            "article_set-1-section": u"1",
    9395            "article_set-2-id": u"3",
    9496            "article_set-2-title": u"Need a title.",
    9597            "article_set-2-content": u"<p>Newest content</p>",
    9698            "article_set-2-date_0": u"2009-03-18",
    9799            "article_set-2-date_1": u"11:54:58",
     100            "article_set-2-section": u"1",
    98101            "article_set-3-id": u"",
    99102            "article_set-3-title": u"",
    100103            "article_set-3-content": u"",
    101104            "article_set-3-date_0": u"",
    102105            "article_set-3-date_1": u"",
     106            "article_set-3-section": u"1",
    103107            "article_set-4-id": u"",
    104108            "article_set-4-title": u"",
    105109            "article_set-4-content": u"",
    106110            "article_set-4-date_0": u"",
    107111            "article_set-4-date_1": u"",
     112            "article_set-4-section": u"1",
    108113            "article_set-5-id": u"",
    109114            "article_set-5-title": u"",
    110115            "article_set-5-content": u"",
    111116            "article_set-5-date_0": u"",
    112117            "article_set-5-date_1": u"",
     118            "article_set-5-section": u"1",
    113119        }
    114120        response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
    115121        self.failUnlessEqual(response.status_code, 302) # redirect somewhere
    116122
     123        # test save_as
     124        post_data.update({'_saveasnew': u'Save+as+new',})
     125        response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
     126        self.failUnlessEqual(response.status_code, 302) # redirect somewhere
     127
     128
    117129    def testChangeListSortingCallable(self):
    118130        """
    119131        Ensure we can sort on a list_display field that is a callable
  • tests/regressiontests/admin_views/models.py

     
    136136
    137137admin.site.register(Article, ArticleAdmin)
    138138admin.site.register(CustomArticle, CustomArticleAdmin)
    139 admin.site.register(Section, inlines=[ArticleInline])
     139admin.site.register(Section, save_as=True, inlines=[ArticleInline])
    140140admin.site.register(ModelWithStringPrimaryKey)
    141141admin.site.register(Color)
    142142admin.site.register(Thing, ThingAdmin)
Back to Top