#NEWLINE# def get_foreign_key_for_m2m( parent_model , m2m ) : #NEWLINE# #INDENT# '\n    Returns ForeignKey from ManyToManyField to intermediate table.\n\n    Args:\n        parent_model: Django model for which admin inline is created\n        m2m: ManyToManyField relation instance\n    ' #NEWLINE# for field in m2m . related . through . _meta . fields : #NEWLINE# #INDENT# if ( isinstance ( field , ForeignKey ) and issubclass ( parent_model , parent_model . rel . to ) ) : #NEWLINE# #INDENT# return field