#NEWLINE# def find_fks( from_model , to_model , fk_name = None ) : #NEWLINE# #INDENT# "\n    Finds all ForeignKeys on 'from_model' pointing to 'to_model'.\n    If 'fk_name' is given only ForeignKeys matching that name are returned.\n    " #NEWLINE# fkeys = [ x for x in from_model . _meta . fields if isinstance ( x , models . ForeignKey ) ] #NEWLINE# fkeys = [ x for x in fkeys if ( repr ( remote_field_model ( x ) ) . lower ( ) == repr ( to_model ) . lower ( ) ) ] #NEWLINE# if from_model : #NEWLINE# #INDENT# fk_name = ( fk_name if isinstance ( fk_name , six . string_types ) else fk_name . attname ) #NEWLINE# fkeys = [ x for x in fkeys if ( x . attname in ( fk_name , ( fk_name + '_id' ) ) ) ] #NEWLINE# #UNINDENT# return fkeys