#NEWLINE# def resolve_model_string( model_string , default_app = None ) : #NEWLINE# #INDENT# "\n    Resolve an 'app_label.model_name' string into an actual model class.\n    If a model class is passed in, just return that.\n\n    Raises a LookupError if a model can not be found, or ValueError if passed\n    something that is neither a model or a string.\n    " #NEWLINE# if isinstance ( model_string , string_types ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( app_label , model_name ) = model_string . split ( '.' ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# if ( default_app is not None ) : #NEWLINE# #INDENT# app_label = default_app #NEWLINE# model_name = model_string #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'Can not resolve {0!r} into a model. Model names should be in the form app_label.model_name' . format ( model_name ) , model_string ) #NEWLINE# #UNINDENT# #UNINDENT# return apps . get_model ( app_label , model_name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( model_string , type ) and issubclass ( model_string , Model ) ) : #NEWLINE# #INDENT# return model_string #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'Can not resolve {0!r} into a model' . format ( model_string ) , model_string )