def update_if_dirty(model_instance, **kwargs):
 dirty = False
 for (key, value) in kwargs.items():
  if (getattr(model_instance, key) != value):
   setattr(model_instance, key, value)
   dirty = True
 if dirty:
  model_instance.save()

def update_if_dirty ( model_instance , ** kwargs ) : dirty = False for ( key , value ) in kwargs . items ( ) : if ( getattr ( model_instance , key ) != value ) : setattr ( model_instance , key , value ) dirty = True if dirty : model_instance . save ( )
updates an instance of a model with kwargs .