#NEWLINE# def preserve_fields_before_update( sender , instance , **kwargs ) : #NEWLINE# #INDENT# if ( instance . pk is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# meta = instance . _meta #NEWLINE# old_instance = meta . model . _default_manager . get ( pk = instance . pk ) #NEWLINE# excluded_fields = [ field . name for field in meta . many_to_many ] #NEWLINE# excluded_fields . append ( meta . pk . name ) #NEWLINE# old_values = model_to_dict ( old_instance , exclude = excluded_fields ) #NEWLINE# setattr ( instance , '_old_values' , old_values )