#NEWLINE# def get_changes_between_models( model1 , model2 , excludes = None ) : #NEWLINE# #INDENT# '\n    Return a dict of differences between two model instances\n    ' #NEWLINE# if ( excludes is None ) : #NEWLINE# #INDENT# excludes = [ ] #NEWLINE# #UNINDENT# changes = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for field in model1 . _meta . fields : #NEWLINE# #INDENT# if ( isinstance ( field , ( fields . AutoField , fields . related . RelatedField ) ) or ( field . name in excludes ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( field . value_from_object ( model1 ) != field . value_from_object ( model2 ) ) : #NEWLINE# #INDENT# changes [ field . verbose_name ] = ( field . value_from_object ( model1 ) , field . value_from_object ( model2 ) ) #NEWLINE# #UNINDENT# #UNINDENT# return changes