Coverage for backend/django/core/auxiliary/methods/copy_object/model_lookup.py: 100%
10 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-07-22 05:22 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-07-22 05:22 +0000
1"""Old-to-new row mappings used by selected-object duplication."""
3from collections.abc import Iterable, Iterator
5from django.db.models import Model
8class ModelLookup:
9 """Map source primary keys to copied model instances."""
11 def __init__(self, object_list: Iterable[Model]):
12 self.model_map = {model.pk: model for model in object_list}
14 def get_model(self, pk: int) -> Model | None:
15 """Return the copied instance for a source primary key."""
17 return self.model_map.get(pk)
19 def __iter__(self) -> Iterator[Model]:
20 return iter(self.model_map.values())
23ModelLookupDict = dict[type[Model], ModelLookup]