#NEWLINE# def test_inline_formsets_save_as_new( self ) : #NEWLINE# #INDENT# AuthorBooksFormSet = inlineformset_factory ( Author , Book , can_delete = False , extra = 2 ) #NEWLINE# author = Author . objects . create ( name = 'Charles Baudelaire' ) #NEWLINE# data = { #NEWLINE# #INDENT# 'book_set-TOTAL_FORMS' : '3' , #NEWLINE# 'book_set-INITIAL_FORMS' : '2' , #NEWLINE# 'book_set-MAX_NUM_FORMS' : '' , #NEWLINE# 'book_set-0-id' : '1' , #NEWLINE# 'book_set-0-title' : 'Les Fleurs du Mal' , #NEWLINE# 'book_set-1-id' : '2' , #NEWLINE# 'book_set-1-title' : 'Les Paradis Artificiels' , #NEWLINE# 'book_set-2-title' : '' , #NEWLINE# #UNINDENT# } #NEWLINE# formset = AuthorBooksFormSet ( data , instance = Author ( ) , save_as_new = True ) #NEWLINE# self . assertTrue ( formset . is_valid ( ) ) #NEWLINE# new_author = Author . objects . create ( name = 'Charles Baudelaire' ) #NEWLINE# formset = AuthorBooksFormSet ( data , instance = book2 , save_as_new = True ) #NEWLINE# saved = formset . save ( ) #NEWLINE# self . assertEqual ( len ( saved ) , 2 ) #NEWLINE# ( book1 , book2 ) = saved #NEWLINE# self . assertEqual ( book1 . title , 'Les Fleurs du Mal' ) #NEWLINE# self . assertEqual ( book2 . title , 'Les Paradis Artificiels' ) #NEWLINE# formset = AuthorBooksFormSet ( prefix = 'test' ) #NEWLINE# self . assertEqual ( len ( formset . forms ) , 2 ) #NEWLINE# self . assertHTMLEqual ( formset . forms [ 0 ] . as_p ( ) , '<p><label for="id_test-0-title">Title:</label> <input id="id_test-0-title" type="text" name="test-0-title" maxlength="100" /><input type="hidden" name="test-0-author" id="id_test-0-author" /><input type="hidden" name="test-0-id" id="id_test-0-id" /></p>' ) #NEWLINE# self . assertHTMLEqual ( formset . forms [ 1 ] . as_p ( ) , '<p><label for="id_test-1-title">Title:</label> <input id="id_test-1-title" type="text" name="test-1-title" maxlength="100" /><input type="hidden" name="test-1-author" id="id_test-1-author" /><input type="hidden" name="test-1-id" id="id_test-1-id" /></p>' )