def snake_case(string):
    ''' Takes a string that represents for example a class name and returns
    the snake case version of it. It is used for model-to-key conversion '''
    s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', string)

    return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()