#NEWLINE# def test_books( self ) : #NEWLINE# #INDENT# author = Author . objects . create ( name = 'John Doe' ) #NEWLINE# for i in range ( 3 ) : #NEWLINE# #INDENT# Book . objects . create ( name = ( 'Book %s' % i ) , author = author ) #NEWLINE# #UNINDENT# for i in Author . objects . prefetch ( 'books' ) . filter ( pk = author . pk ) : #NEWLINE# #INDENT# self . assertTrue ( hasattr ( i , 'prefetched_books' ) ) #NEWLINE# self . assertEqual ( len ( i . books ) , 3 , i . books ) #NEWLINE# #UNINDENT# for i in Author . objects . filter ( pk = author . pk ) : #NEWLINE# #INDENT# self . assertFalse ( hasattr ( i , 'prefetched_books' ) ) #NEWLINE# self . assertEqual ( len ( i . books ) , 3 , i . books )