Receives the one of the types of items and parses them as to achieve a end situation with one excludable per alias/model in relation. Each excludable has three sets of values - include, exclude, and flatten. :param items: values to be included, excluded or flattene
(
self,
items: Union[list[str], str, tuple[str], set[str], dict],
model_cls: type["Model"],
slot: Slot = "include",
)
| 500 | return excludable |
| 501 | |
| 502 | def build( |
| 503 | self, |
| 504 | items: Union[list[str], str, tuple[str], set[str], dict], |
| 505 | model_cls: type["Model"], |
| 506 | slot: Slot = "include", |
| 507 | ) -> None: |
| 508 | """ |
| 509 | Receives the one of the types of items and parses them as to achieve |
| 510 | a end situation with one excludable per alias/model in relation. |
| 511 | |
| 512 | Each excludable has three sets of values - include, exclude, and flatten. |
| 513 | |
| 514 | :param items: values to be included, excluded or flattened |
| 515 | :type items: Union[list[str], str, tuple[str], set[str], dict] |
| 516 | :param model_cls: source model from which relations are constructed |
| 517 | :type model_cls: ormar.models.metaclass.ModelMetaclass |
| 518 | :param slot: which slot to write parsed values into |
| 519 | :type slot: Slot |
| 520 | """ |
| 521 | if isinstance(items, str): |
| 522 | items = {items} |
| 523 | |
| 524 | if isinstance(items, dict): |
| 525 | self._traverse_dict( |
| 526 | values=items, |
| 527 | source_model=model_cls, |
| 528 | model_cls=model_cls, |
| 529 | slot=slot, |
| 530 | ) |
| 531 | else: |
| 532 | items = set(items) |
| 533 | nested_items = set(x for x in items if "__" in x) |
| 534 | items.difference_update(nested_items) |
| 535 | if items: |
| 536 | self._set_slot( |
| 537 | items=items, |
| 538 | model_cls=model_cls, |
| 539 | slot=slot, |
| 540 | ) |
| 541 | if nested_items: |
| 542 | self._traverse_list(values=nested_items, model_cls=model_cls, slot=slot) |
| 543 | |
| 544 | if slot == "flatten": |
| 545 | self._validate_flatten_prefix_collisions() |
| 546 | |
| 547 | def _set_slot( |
| 548 | self, |