Resolve a dunder path prefix to its target ``(alias, model)``. An empty prefix returns ``("", source_model)``. Goes through :func:`get_relationship_alias_model_and_str`, which mutates its ``related_parts`` argument while resolving through models - the prefix
(
source_model: type["Model"],
parts_prefix: tuple,
)
| 397 | |
| 398 | @staticmethod |
| 399 | def _resolve_path( |
| 400 | source_model: type["Model"], |
| 401 | parts_prefix: tuple, |
| 402 | ) -> tuple[str, type["Model"]]: |
| 403 | """ |
| 404 | Resolve a dunder path prefix to its target ``(alias, model)``. |
| 405 | |
| 406 | An empty prefix returns ``("", source_model)``. Goes through |
| 407 | :func:`get_relationship_alias_model_and_str`, which mutates its |
| 408 | ``related_parts`` argument while resolving through models - the |
| 409 | prefix tuple is copied to a list to insulate the caller. |
| 410 | |
| 411 | Examples (alias strings are hashes from the alias manager and |
| 412 | shown here as ``<...>`` since they are not stable across runs):: |
| 413 | |
| 414 | _resolve_path(Post, ()) |
| 415 | # => ("", Post) |
| 416 | |
| 417 | _resolve_path(Post, ("category",)) |
| 418 | # => ("<post_category>", Category) |
| 419 | |
| 420 | _resolve_path(Role, ("users", "categories")) |
| 421 | # => ("<usercategory_category>", Category) |
| 422 | |
| 423 | :param source_model: model from which the path is rooted |
| 424 | :type source_model: type[Model] |
| 425 | :param parts_prefix: pre-split path segments |
| 426 | :type parts_prefix: tuple |
| 427 | :return: alias and target model at the prefix |
| 428 | :rtype: tuple[str, type[Model]] |
| 429 | """ |
| 430 | if not parts_prefix: |
| 431 | return "", source_model |
| 432 | alias, model, _, _ = get_relationship_alias_model_and_str( |
| 433 | source_model=source_model, |
| 434 | related_parts=list(parts_prefix), |
| 435 | ) |
| 436 | return alias, model |
| 437 | |
| 438 | def _referenced_at( |
| 439 | self, |
no test coverage detected