Early initialization of Tortoise ORM Models for a single app. :param label: The app label, e.g. 'models' :param model_paths: Models paths to initialize :param _init_relations: Whether to init relations or not
(
cls,
label: str,
model_paths: Iterable[ModuleType | str],
_init_relations: bool = True,
)
| 232 | |
| 233 | @classmethod |
| 234 | def init_app( |
| 235 | cls, |
| 236 | label: str, |
| 237 | model_paths: Iterable[ModuleType | str], |
| 238 | _init_relations: bool = True, |
| 239 | ) -> dict[str, type[Model]]: |
| 240 | """ |
| 241 | Early initialization of Tortoise ORM Models for a single app. |
| 242 | |
| 243 | :param label: The app label, e.g. 'models' |
| 244 | :param model_paths: Models paths to initialize |
| 245 | :param _init_relations: Whether to init relations or not |
| 246 | """ |
| 247 | from tortoise.context import TortoiseContext, get_current_context |
| 248 | |
| 249 | # Get or create context |
| 250 | ctx = get_current_context() |
| 251 | if ctx is None: |
| 252 | ctx = TortoiseContext() |
| 253 | ctx.__enter__() |
| 254 | |
| 255 | # Create Apps if not exists |
| 256 | if ctx._apps is None: |
| 257 | ctx._apps = Apps({}, ctx.connections, cls.table_name_generator) |
| 258 | ctx._apps._table_name_generator = cls.table_name_generator |
| 259 | return ctx._apps.init_app(label, model_paths, _init_relations=_init_relations) |
| 260 | |
| 261 | @classmethod |
| 262 | def _init_apps( |
no test coverage detected