You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
601 B

  1. from typing import Dict, List
  2. from pydantic import UUID4
  3. from examples.models import Example
  4. class Examples:
  5. def __init__(self, examples: List[Example]):
  6. self.examples = examples
  7. self.uuid_to_example: Dict[UUID4, Example] = {}
  8. def __getitem__(self, uuid: UUID4) -> Example:
  9. return self.uuid_to_example[uuid]
  10. def __contains__(self, uuid: UUID4) -> bool:
  11. return uuid in self.uuid_to_example
  12. def save(self):
  13. examples = Example.objects.bulk_create(self.examples)
  14. self.uuid_to_example = {example.uuid: example for example in examples}