def import_all_models(package_name='indico'): """Utility that imports all modules in indico/**/models/ :param package_name: Package name to scan for models. If unset, the top-level package containing this file is used. """ package_root = get_package_root_path(package_name) if not package_root: return modules = [] for root, dirs, files in os.walk(package_root): if os.path.basename(root) == 'models': package = os.path.relpath(root, package_root).replace(os.sep, '.') modules += ['{}.{}.{}'.format(package_name, package, name[:-3]) for name in files if name.endswith('.py') and name != '__init__.py' and not name.endswith('_test.py')] for module in modules: import_module(module)