Uses django.db.djmodels.get_app and fuzzywuzzy to get the models module for a django app

    Retrieve an app module from an app name string, even if mispelled (uses fuzzywuzzy to find the best match)
    To get a list of all the apps use `get_app(None)` or `get_app([]) or get_app(())`
    To get a single random app use `get_app('')`

    >>> get_app('call').__class__.__name__ == 'module'
    True
    >>> get_app('model').__name__ == 'miner.models'
    True
    >>> isinstance(get_app('whatever'), ModuleType)
    True
    >>> isinstance(get_app(''), ModuleType)
    True
    isinstance(get_app(), ModuleType)
    False
    isinstance(get_app(), list)
    True

def get_app(app=None, verbosity=0):
    """Uses django.db.djmodels.get_app and fuzzywuzzy to get the models module for a django app

    Retrieve an app module from an app name string, even if mispelled (uses fuzzywuzzy to find the best match)
    To get a list of all the apps use `get_app(None)` or `get_app([]) or get_app(())`
    To get a single random app use `get_app('')`

    >>> get_app('call').__class__.__name__ == 'module'
    True
    >>> get_app('model').__name__ == 'miner.models'
    True
    >>> isinstance(get_app('whatever'), ModuleType)
    True
    >>> isinstance(get_app(''), ModuleType)
    True
    isinstance(get_app(), ModuleType)
    False
    isinstance(get_app(), list)
    True
    """
    # print 'get_app(', app
    if not app:
        # for an empty list, tuple or None, just get all apps
        if isinstance(app, (type(None), list, tuple)):
            return [app_class.__package__ for app_class in djmodels.get_apps() if app_class and app_class.__package__]
        # for a blank string, get the default app(s)
        else:
            if get_app.default:
                return get_app(get_app.default)
            else:
                return djmodels.get_apps()[-1]
    elif isinstance(app, ModuleType):
        return app
    elif isinstance(app, basestring):
        if app.strip().endswith('.models'):
            return get_app(app[:-len('.models')])
        elif '.' in app:
            return get_app('.'.join(app.split('.')[1:]))  # django.db.models only looks at the module name in the INSTALLED_APPS list!         
    try:
        if verbosity > 1:
            print 'Attempting django.db.models.get_app(%r)' % app
        return djmodels.get_app(app)
    except ImproperlyConfigured:
        if verbosity > 0:
            print 'WARNING: unable to find app = %r' % app
    if verbosity > 2:
        print 'Trying a fuzzy match on app = %r' % app
    app_names = [app_class.__package__ for app_class in djmodels.get_apps() if app_class and app_class.__package__]
    fuzzy_app_name = fuzzy.extractOne(str(app), app_names)[0]
    if verbosity > 0:
        print 'WARNING: Best fuzzy match for app name %r is %s' % (app, fuzzy_app_name)
    return djmodels.get_app(fuzzy_app_name.split('.')[-1])