<s> from __future__ import unicode_literals <EOL> from importlib import import_module <EOL> from django . apps import apps <EOL> from django . apps . config import MODELS_MODULE_NAME <EOL> from django . core . exceptions import AppRegistryNotReady <EOL> def get_model ( app_label , model_name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return apps . get_model ( app_label , model_name ) <EOL> except AppRegistryNotReady : <EOL> if apps . apps_ready and not apps . models_ready : <EOL> app_config = apps . get_app_config ( app_label ) <EOL> import_module ( '<STR_LIT>' % ( app_config . name , MODELS_MODULE_NAME ) ) <EOL> return apps . get_registered_model ( app_label , model_name ) <EOL> else : <EOL> raise <EOL> def is_model_registered ( app_label , model_name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> apps . get_registered_model ( app_label , model_name ) <EOL> except LookupError : <EOL> return False <EOL> else : <EOL> return True <EOL> def model_factory ( abstract_class ) : <EOL> """<STR_LIT>""" <EOL> app_label = abstract_class . Meta . app_label <EOL> model_name = abstract_class . __name__ . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not is_model_registered ( app_label , model_name ) : <EOL> return type ( str ( model_name ) , ( abstract_class , ) , { '<STR_LIT>' : __name__ , } ) </s>
