MCPcopy Create free account
hub / github.com/tortoise/tortoise-orm / get_related_model

Method get_related_model

tortoise/apps.py:127–146  ·  view source on GitHub ↗

Test, if app and model really exist. Throws a ConfigurationError with a hopefully helpful message. If successful, returns the requested model. :raises ConfigurationError: If no such app exists.

(related_app_name: str, related_model_name: str)

Source from the content-addressed store, hash-verified

125
126 def _init_relations(self) -> None:
127 def get_related_model(related_app_name: str, related_model_name: str) -> type[Model]:
128 """
129 Test, if app and model really exist. Throws a ConfigurationError with a hopefully
130 helpful message. If successful, returns the requested model.
131
132 :raises ConfigurationError: If no such app exists.
133 """
134 try:
135 return self.apps[related_app_name][related_model_name]
136 except KeyError:
137 if related_app_name not in self.apps:
138 raise ConfigurationError(
139 f"No app with name '{related_app_name}' registered."
140 f" Please check your model names in ForeignKeyFields"
141 f" and configurations."
142 )
143 raise ConfigurationError(
144 f"No model with name '{related_model_name}' registered in"
145 f" app '{related_app_name}'."
146 )
147
148 def split_reference(reference: str) -> tuple[str, str]:
149 """

Callers

nothing calls this directly

Calls 1

ConfigurationErrorClass · 0.90

Tested by

no test coverage detected