#NEWLINE# def test_prefetch_related( self ) : #NEWLINE# #INDENT# Band . objects . create ( name = 'The Beatles' , members = [ BandMember ( id = 1 , name = 'John Lennon' ) , BandMember ( id = 2 , name = 'Paul McCartney' ) ] ) #NEWLINE# with self . assertNumQueries ( 2 ) : #NEWLINE# #INDENT# lists = [ list ( band . members . all ( ) ) for band in Band . objects . prefetch_related ( 'members' ) ] #NEWLINE# #UNINDENT# normal_lists = [ list ( band . members . all ( ) ) for band in Band . objects . all ( ) ] #NEWLINE# self . assertEqual ( lists , normal_lists )