#NEWLINE# def test_reference_linking( ) : #NEWLINE# #INDENT# ( app , db , admin ) = setup ( ) #NEWLINE# class Person ( db . Model ) : #NEWLINE# #INDENT# id = db . Column ( db . Integer , primary_key = True ) #NEWLINE# name = db . Column ( db . String ( 20 ) ) #NEWLINE# pet = db . relationship ( 'Dog' , uselist = False , backref = 'person' ) #NEWLINE# def __init__( self , name = None ) : #NEWLINE# #INDENT# self . name = name #NEWLINE# #UNINDENT# #UNINDENT# class Dog ( db . Model ) : #NEWLINE# #INDENT# id = db . Column ( db . Integer , primary_key = True ) #NEWLINE# name = db . Column ( db . String ( 20 ) ) #NEWLINE# person_id = db . Column ( db . Integer , db . ForeignKey ( 'person.id' ) ) #NEWLINE# def __init__( self , name = None , person_id = None ) : #NEWLINE# #INDENT# self . name = name #NEWLINE# self . person_id = person_id #NEWLINE# #UNINDENT# def __unicode__( self ) : #NEWLINE# #INDENT# return self . name #NEWLINE# #UNINDENT# #UNINDENT# db . create_all ( ) #NEWLINE# class DogAdmin ( ModelAdmin ) : #NEWLINE# #INDENT# session = db . session #NEWLINE# #UNINDENT# class PersonAdmin ( ModelAdmin ) : #NEWLINE# #INDENT# list_display = ( 'name' , 'pet' ) #NEWLINE# fields = ( 'name' , 'pet' ) #NEWLINE# readonly_fields = ( 'pet' , ) #NEWLINE# session = db . session #NEWLINE# #UNINDENT# db . session . add ( Person ( name = 'Stan' ) ) #NEWLINE# db . session . commit ( ) #NEWLINE# person = db . session . query ( Person ) . first ( ) #NEWLINE# db . session . add ( Dog ( name = 'Sparky' , person_id = person . id ) ) #NEWLINE# db . session . commit ( ) #NEWLINE# person = db . session . query ( Person ) . first ( ) #NEWLINE# dog = db . session . query ( Dog ) . first ( ) #NEWLINE# admin . register ( Dog , DogAdmin , name = 'Dogs' ) #NEWLINE# admin . register ( Person , PersonAdmin , name = 'People' ) #NEWLINE# client = app . test_client ( ) #NEWLINE# resp = client . get ( '/admin/person/' ) #NEWLINE# dog_link = ( '<a href="/admin/dog/%s/">Sparky</a>' % dog . id ) #NEWLINE# ok_ ( ( dog_link in resp . data ) ) #NEWLINE# resp = client . get ( ( '/admin/person/%s/' % person . id ) ) #NEWLINE# ok_ ( ( '<input class="" id="name" name="name" type="text" value="Stan">' in resp . data ) ) #NEWLINE# ok_ ( ( dog_link in resp . data ) )