#NEWLINE# def test_multiple_foreignkeys( self ) : #NEWLINE# #INDENT# c1 = Category . objects . create ( name = 'First' ) #NEWLINE# c2 = Category . objects . create ( name = 'Second' ) #NEWLINE# c3 = Category . objects . create ( name = 'Third' ) #NEWLINE# r1 = Record . objects . create ( category = c1 ) #NEWLINE# r2 = Record . objects . create ( category = c1 ) #NEWLINE# r3 = Record . objects . create ( category = c2 ) #NEWLINE# r4 = Record . objects . create ( category = c2 ) #NEWLINE# r5 = Record . objects . create ( category = c3 ) #NEWLINE# Relation . objects . create ( left = r1 , right = r2 ) #NEWLINE# Relation . objects . create ( left = r3 , right = r4 ) #NEWLINE# Relation . objects . create ( left = r1 , right = r3 ) #NEWLINE# Relation . objects . create ( left = r5 , right = r2 ) #NEWLINE# Relation . objects . create ( left = r3 , right = r2 ) #NEWLINE# q1 = Relation . objects . filter ( left__category__name__in = [ 'First' ] , right__category__name__in = [ 'Second' ] ) #NEWLINE# self . assertQuerysetEqual ( q1 , [ '<Relation: First - Second>' ] ) #NEWLINE# q2 = Category . objects . filter ( record__left_set__right__category__name = 'Second' ) . order_by ( 'name' ) #NEWLINE# self . assertQuerysetEqual ( q2 , [ '<Category: First>' , '<Category: Second>' ] ) #NEWLINE# p = Parent . objects . create ( name = 'Parent' ) #NEWLINE# c = Child . objects . create ( name = 'Child' , parent = p ) #NEWLINE# with self . assertRaises ( ValueError ) : #NEWLINE# #INDENT# Child . objects . create ( name = 'Grandchild' , parent = c )