5.0 KiB
models.excludable
Excludable Objects
@dataclass
class Excludable()
Class that keeps sets of fields to exclude and include
get_copy
| get_copy() -> "Excludable"
Return copy of self to avoid in place modifications
Returns:
ormar.models.excludable.Excludable: copy of self with copied sets
set_values
| set_values(value: Set, is_exclude: bool) -> None
Appends the data to include/exclude sets.
Arguments:
value(set): set of values to addis_exclude(bool): flag if values are to be excluded or included
is_included
| is_included(key: str) -> bool
Check if field in included (in set or set is {...})
Arguments:
key(str): key to check
Returns:
bool: result of the check
is_excluded
| is_excluded(key: str) -> bool
Check if field in excluded (in set or set is {...})
Arguments:
key(str): key to check
Returns:
bool: result of the check
ExcludableItems Objects
class ExcludableItems()
Keeps a dictionary of Excludables by alias + model_name keys to allow quick lookup by nested models without need to travers deeply nested dictionaries and passing include/exclude around
from_excludable
| @classmethod
| from_excludable(cls, other: "ExcludableItems") -> "ExcludableItems"
Copy passed ExcludableItems to avoid inplace modifications.
Arguments:
other(ormar.models.excludable.ExcludableItems): other excludable items to be copied
Returns:
ormar.models.excludable.ExcludableItems: copy of other
include_entry_count
| include_entry_count() -> int
Returns count of include items inside
get
| get(model_cls: Type["Model"], alias: str = "") -> Excludable
Return Excludable for given model and alias.
Arguments:
model_cls(ormar.models.metaclass.ModelMetaclass): target model to checkalias(str): table alias from relation manager
Returns:
ormar.models.excludable.Excludable: Excludable for given model and alias
build
| build(items: Union[List[str], str, Tuple[str], Set[str], Dict], model_cls: Type["Model"], is_exclude: bool = False) -> None
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 two sets of values - one to include, one to exclude.
Arguments:
items(Union[List[str], str, Tuple[str], Set[str], Dict]): values to be included or excludedmodel_cls(ormar.models.metaclass.ModelMetaclass): source model from which relations are constructedis_exclude(bool): flag if items should be included or excluded
_set_excludes
| _set_excludes(items: Set, model_name: str, is_exclude: bool, alias: str = "") -> None
Sets set of values to be included or excluded for given key and model.
Arguments:
items(set): items to include/excludemodel_name(str): name of model to construct keyis_exclude(bool): flag if values should be included or excludedalias(str):
_traverse_dict
| _traverse_dict(values: Dict, source_model: Type["Model"], model_cls: Type["Model"], is_exclude: bool, related_items: List = None, alias: str = "") -> None
Goes through dict of nested values and construct/update Excludables.
Arguments:
values(Dict): items to include/excludesource_model(ormar.models.metaclass.ModelMetaclass): source model from which relations are constructedmodel_cls(ormar.models.metaclass.ModelMetaclass): model from which current relation is constructedis_exclude(bool): flag if values should be included or excludedrelated_items(List): list of names of related fields chainalias(str): alias of relation
_traverse_list
| _traverse_list(values: Set[str], model_cls: Type["Model"], is_exclude: bool) -> None
Goes through list of values and construct/update Excludables.
Arguments:
values(set): items to include/excludemodel_cls(ormar.models.metaclass.ModelMetaclass): model from which current relation is constructedis_exclude(bool): flag if values should be included or excluded