Return whether this :class:`ExcludableItems` already carries any include or exclude entry for the model at ``parts_prefix``. Used by :meth:`with_projection_exclusions` to detect whether the user's ``fields()`` call referenced a given path - an empty ``Exclud
(
self,
source_model: type["Model"],
parts_prefix: tuple,
)
| 436 | return alias, model |
| 437 | |
| 438 | def _referenced_at( |
| 439 | self, |
| 440 | source_model: type["Model"], |
| 441 | parts_prefix: tuple, |
| 442 | ) -> bool: |
| 443 | """ |
| 444 | Return whether this :class:`ExcludableItems` already carries any |
| 445 | include or exclude entry for the model at ``parts_prefix``. |
| 446 | |
| 447 | Used by :meth:`with_projection_exclusions` to detect whether the |
| 448 | user's ``fields()`` call referenced a given path - an empty |
| 449 | ``Excludable`` (or none at all) means "not referenced". |
| 450 | |
| 451 | Examples, contrasting the same path under two different |
| 452 | ``fields()`` specs:: |
| 453 | |
| 454 | # Built from Post.objects.fields(["name"]) |
| 455 | # items = {"post": Excludable(include={"name"})} |
| 456 | |
| 457 | excludable._referenced_at(Post, ()) |
| 458 | # => True (Post has a non-empty include) |
| 459 | |
| 460 | excludable._referenced_at(Post, ("category",)) |
| 461 | # => False (no entry for Category) |
| 462 | |
| 463 | |
| 464 | # Built from Post.objects.fields(["name", "category__name"]) |
| 465 | # items = { |
| 466 | # "post": Excludable(include={"name"}), |
| 467 | # "<alias>_category": Excludable(include={"name"}), |
| 468 | # } |
| 469 | |
| 470 | excludable._referenced_at(Post, ("category",)) |
| 471 | # => True (Category has a non-empty include) |
| 472 | |
| 473 | :param source_model: model from which the path is rooted |
| 474 | :type source_model: type[Model] |
| 475 | :param parts_prefix: pre-split path segments to check |
| 476 | :type parts_prefix: tuple |
| 477 | :return: True if a non-empty entry exists at the prefix |
| 478 | :rtype: bool |
| 479 | """ |
| 480 | alias, model = self._resolve_path(source_model, parts_prefix) |
| 481 | exc = self.items.get(self._make_key(model, alias)) |
| 482 | return exc is not None and bool(exc.include or exc.exclude) |
| 483 | |
| 484 | def get(self, model_cls: type["Model"], alias: str = "") -> Excludable: |
| 485 | """ |
no test coverage detected