#NEWLINE# def test_prefetch_related_m2m_reverse_works( self ) : #NEWLINE# #INDENT# Membership . objects . create ( membership_country = self . usa , person = self . bob , group = self . cia ) #NEWLINE# Membership . objects . create ( membership_country = self . usa , person = self . jim , group = self . democrat ) #NEWLINE# with self . assertNumQueries ( 2 ) : #NEWLINE# #INDENT# groups_lists = [ list ( p . groups . all ( ) ) for p in Person . objects . prefetch_related ( 'groups' ) ] #NEWLINE# #UNINDENT# normal_groups_lists = [ list ( p . groups . all ( ) ) for p in Person . objects . all ( ) ] #NEWLINE# self . assertEqual ( groups_lists , normal_groups_lists )