def get_class_by_tablename(tablename, db):
    """Return class reference mapped to table.

    :param tablename: String with name of table.
    :return: Class reference or None.
    """
    for c in db.Model._decl_class_registry.values():
        if hasattr(c, '__tablename__') and c.__tablename__ == tablename:
            return c

    # This sort of prints the schema
    # for t in db.metadata.tables.items():
    #         print(t)

    # print(get_class_by_tablename("products"))