#NEWLINE# def test_regression_12851( self ) : #NEWLINE# #INDENT# '\n        Regression for #12851\n\n        Deferred fields are used correctly if you select_related a subset\n        of fields.\n        ' #NEWLINE# australia = Country . objects . create ( name = 'Australia' ) #NEWLINE# active = ClientStatus . objects . create ( name = 'active' ) #NEWLINE# wa = State . objects . create ( name = 'Western Australia' , country = australia ) #NEWLINE# c1 = Client . objects . create ( name = 'Brian Burke' , state = wa , status = active ) #NEWLINE# burke = Client . objects . select_related ( 'state' ) . defer ( 'state__name' ) . get ( name = 'Brian Burke' ) #NEWLINE# self . assertEqual ( burke . name , 'Brian Burke' ) #NEWLINE# self . assertEqual ( burke . state . name , 'Western Australia' ) #NEWLINE# sc1 = SpecialClient . objects . create ( name = 'Troy Buswell' , state = wa , status = active , value = 42 ) #NEWLINE# troy = SpecialClient . objects . select_related ( 'state' ) . defer ( 'state__name' ) . get ( name = 'Troy Buswell' ) #NEWLINE# self . assertEqual ( troy . name , 'Troy Buswell' ) #NEWLINE# self . assertEqual ( troy . value , 42 ) #NEWLINE# self . assertEqual ( troy . state . name , 'Western Australia' ) #NEWLINE# troy = SpecialClient . objects . select_related ( 'state' ) . defer ( 'value' , 'state__name' ) . get ( name = 'Troy Buswell' ) #NEWLINE# self . assertEqual ( troy . name , 'Troy Buswell' ) #NEWLINE# self . assertEqual ( troy . value , 42 ) #NEWLINE# self . assertEqual ( troy . state . name , 'Western Australia' ) #NEWLINE# troy = SpecialClient . objects . select_related ( 'state' ) . only ( 'name' ) . get ( name = 'Troy Buswell' ) #NEWLINE# self . assertEqual ( troy . name , 'Troy Buswell' ) #NEWLINE# self . assertEqual ( troy . value , 42 ) #NEWLINE# self . assertEqual ( troy . state . name , 'Western Australia' )