#NEWLINE# def add_lazy_relation( cls , field , relation , operation ) : #NEWLINE# #INDENT# '\n    Adds a lookup on ``cls`` when a related field is defined using a string,\n    i.e.::\n\n        class MyModel(Model):\n            fk = ForeignKey("AnotherModel")\n\n    This string can be:\n\n        * RECURSIVE_RELATIONSHIP_CONSTANT (i.e. "self") to indicate a recursive\n          relation.\n\n        * The name of a model (i.e "AnotherModel") to indicate another model in\n          the same app.\n\n        * An app-label and model name (i.e. "someapp.AnotherModel") to indicate\n          another model in a different app.\n\n    If the other model hasn\'t yet been loaded -- almost a given if you\'re using\n    lazy relationships -- then the relation won\'t be set up until the\n    class_prepared signal fires at the end of model initialization.\n\n    operation is the work that must be performed once the relation can be resolved.\n    ' #NEWLINE# if ( relation == RECURSIVE_RELATIONSHIP_CONSTANT ) : #NEWLINE# #INDENT# app_label = cls . _meta . app_label #NEWLINE# model_name = cls . __name__ #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( relation , six . string_types ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( app_label , model_name ) = relation . split ( '.' ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# app_label = cls . _meta . app_label #NEWLINE# model_name = relation #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# app_label = relation . _meta . app_label #NEWLINE# model_name = relation . _meta . object_name #NEWLINE# #UNINDENT# #UNINDENT# model = get_model ( app_label , model_name , seed_cache = False , only_installed = False ) #NEWLINE# if model : #NEWLINE# #INDENT# operation ( field , model , cls ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# key = ( app_label , model_name ) #NEWLINE# value = ( cls , field , operation ) #NEWLINE# pending_lookups . setdefault ( key , [ ] ) . append ( value )