def cache_model(model, timeout=None):
 if hasattr(model, 'get_cached'):
  return
 def clear_cache(sender, instance, *args, **kwargs):
  '\n        Clears the cache for the given instance.\n        '
  delete_instance(sender, instance)
 post_save.connect(clear_cache, sender=model, weak=False)
 post_delete.connect(clear_cache, sender=model, weak=False)
 @classmethod
 def get(cls, pk, using=None):
  '\n        Returns the model for the given primary key (pk).\n        '
  if (pk is None):
   return None
  return get_instance(cls, pk, timeout, using)
 model.get_cached = get

def cache_model ( model , timeout = None ) : if hasattr ( model , 'get_cached' ) : return def clear_cache ( sender , instance , * args , ** kwargs ) : delete_instance ( sender , instance ) post_save . connect ( clear_cache , sender = model , weak = False ) post_delete . connect ( clear_cache , sender = model , weak = False ) @ classmethod def get ( cls , pk , using = None ) : if ( pk is None ) : return None return get_instance ( cls , pk , timeout , using ) model . get_cached = get
adds utility methods to the given model to obtain foreignkey instances via the cache .