(self)
| 86 | return self.apps[label] |
| 87 | |
| 88 | def _load_from_config(self) -> None: |
| 89 | if self._connections is None: |
| 90 | raise ConfigurationError("ConnectionHandler is required to load from config") |
| 91 | for name, info in self._config.items(): |
| 92 | default_connection = info.get("default_connection", "default") |
| 93 | if self._validate_connections: |
| 94 | try: |
| 95 | self._connections.get(default_connection) |
| 96 | except KeyError: |
| 97 | raise ConfigurationError( |
| 98 | f'Unknown connection "{default_connection}" for app "{name}"' |
| 99 | ) |
| 100 | else: |
| 101 | if default_connection not in self._connections.db_config: |
| 102 | raise ConfigurationError( |
| 103 | f'Unknown connection "{default_connection}" for app "{name}"' |
| 104 | ) |
| 105 | |
| 106 | self.init_app(name, info["models"], _init_relations=False) |
| 107 | |
| 108 | for model in self.apps[name].values(): |
| 109 | model._meta.default_connection = default_connection |
| 110 | |
| 111 | self._init_relations() |
| 112 | if self._validate_connections: |
| 113 | self._build_initial_querysets() |
| 114 | |
| 115 | def _build_initial_querysets(self) -> None: |
| 116 | for app in self.apps.values(): |
no test coverage detected