<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_app_name(mod_name):
 """ Retrieve application name from models.py module path 'testapp' 'testapp' instead of 'some.testapp' for compatibility: 'testapp' 'testapp' 'testapp' 'testapp' """

    rparts = list(reversed(mod_name.split('.')))
    try:
        try:
            return rparts[rparts.index(MODELS_MODULE_NAME) + 1]
        except ValueError:
            # MODELS_MODULE_NAME ('models' string) is not found
            return rparts[1]
    except IndexError:
        # Some weird model naming scheme like in Sentry.
        return mod_name