#NEWLINE# def test_using_is_honored_m2m( self ) : #NEWLINE# #INDENT# B = Book . objects . using ( 'other' ) #NEWLINE# A = Author . objects . using ( 'other' ) #NEWLINE# book1 = B . create ( title = 'Poems' ) #NEWLINE# book2 = B . create ( title = 'Jane Eyre' ) #NEWLINE# book3 = B . create ( title = 'Wuthering Heights' ) #NEWLINE# book4 = B . create ( title = 'Sense and Sensibility' ) #NEWLINE# author1 = A . create ( name = 'Charlotte' , first_book = book1 ) #NEWLINE# author2 = A . create ( name = 'Anne' , first_book = book1 ) #NEWLINE# author3 = A . create ( name = 'Emily' , first_book = book1 ) #NEWLINE# author4 = A . create ( name = 'Jane' , first_book = book4 ) #NEWLINE# book1 . authors . add ( author1 , author2 , author3 ) #NEWLINE# book2 . authors . add ( author1 ) #NEWLINE# book3 . authors . add ( author3 ) #NEWLINE# book4 . authors . add ( author4 ) #NEWLINE# qs1 = B . prefetch_related ( 'authors' ) #NEWLINE# with self . assertNumQueries ( 2 , using = 'other' ) : #NEWLINE# #INDENT# books = '' . join ( [ ( '%s (%s)\n' % ( book . title , ', ' . join ( ( a . name for a in book . authors . all ( ) ) ) ) ) for book in qs1 ] ) #NEWLINE# #UNINDENT# self . assertEqual ( books , 'Poems (Charlotte, Anne, Emily)\nJane Eyre (Charlotte)\nWuthering Heights (Emily)\nSense and Sensibility (Jane)\n' ) #NEWLINE# qs2 = A . prefetch_related ( 'books' ) #NEWLINE# with self . assertNumQueries ( 2 , using = 'other' ) : #NEWLINE# #INDENT# authors = '' . join ( [ ( '%s: %s\n' % ( author . name , ', ' . join ( ( b . title for b in author . books . all ( ) ) ) ) ) for author in qs2 ] ) #NEWLINE# #UNINDENT# self . assertEqual ( authors , 'Charlotte: Poems, Jane Eyre\nAnne: Poems\nEmily: Poems, Wuthering Heights\nJane: Sense and Sensibility\n' )