(root_model, path)
return root_model
Return a model class for a related model
    root_model is the class of the initial model
    path is like foo__bar where bar is related to foo
Return a model class for a related model
    root_model is the class of the initial model
    path is like foo__bar where bar is related to foo
Return a model class for a related model root_model is the class of the initial model path is like foo__bar where bar is related to foo
def get_model_from_path_string(root_model, path):
    """ Return a model class for a related model
    root_model is the class of the initial model
    path is like foo__bar where bar is related to foo
    """
    for path_section in path.split('__'):
        if path_section:
            try:
                field = root_model._meta.get_field(path_section)
                direct = field.concrete
            except FieldDoesNotExist:
                return root_model
            if direct:
                if hasattr(field, 'related'):
                    try:
                        root_model = field.related.parent_model()
                    except AttributeError:
                        root_model = field.related.model

                elif hasattr(field, 'related_model') and field.related_model:
                    root_model = field.related_model

            else:
                if hasattr(field, 'related_model'):
                    root_model = field.related_model
                else:
                    root_model = field.model
    return root_model
def get_model_from_path_string ( root_model , path ) : for path_section in path . split ( '__' ) : if path_section : try : field = root_model . _meta . get_field ( path_section ) direct = field . concrete except FieldDoesNotExist : return root_model if direct : if hasattr ( field , 'related' ) : try : root_model = field . related . parent_model ( ) except AttributeError : root_model = field . related . model elif hasattr ( field , 'related_model' ) and field . related_model : root_model = field . related_model else : if hasattr ( field , 'related_model' ) : root_model = field . related_model else : root_model = field . model return root_model