def get_changed_fields_dict(instance, model_class):
 try:
  old_model = model_class.objects.get(pk=instance.pk)
 except model_class.DoesNotExist:
  return {}
 else:
  field_names = [f.name for f in model_class._meta.get_fields() if (not f.is_relation)]
  changed_fields = {field_name: getattr(old_model, field_name) for field_name in field_names if (getattr(old_model, field_name) != getattr(instance, field_name))}
  return changed_fields

def get_changed_fields_dict ( instance , model_class ) : try : old_model = model_class . objects . get ( pk = instance . pk ) except model_class . DoesNotExist : return { } else : field_names = [ f . name for f in model_class . _meta . get_fields ( ) if ( not f . is_relation ) ] changed_fields = { field_name : getattr ( old_model , field_name ) for field_name in field_names if ( getattr ( old_model , field_name ) != getattr ( instance , field_name ) ) } return changed_fields
helper method for tracking field changes on a model .