Skip to content

models.excludable

Excludable Objects

1
2
@dataclass
class Excludable()

Class that keeps sets of fields to exclude and include

get_copy

1
 | get_copy() -> "Excludable"

Return copy of self to avoid in place modifications

Returns:

copy of self with copied sets :rtype: ormar.models.excludable.Excludable

set_values

1
 | set_values(value: Set, is_exclude: bool) -> None

Appends the data to include/exclude sets.

Arguments:

  • value: set of values to add :type value: set
  • is_exclude: flag if values are to be excluded or included :type is_exclude: bool

is_included

1
 | is_included(key: str) -> bool

Check if field in included (in set or set is {...})

Arguments:

  • key: key to check :type key: str

Returns:

result of the check :rtype: bool

is_excluded

1
 | is_excluded(key: str) -> bool

Check if field in excluded (in set or set is {...})

Arguments:

  • key: key to check :type key: str

Returns:

result of the check :rtype: bool

ExcludableItems Objects

1
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

1
2
 | @classmethod
 | from_excludable(cls, other: "ExcludableItems") -> "ExcludableItems"

Copy passed ExcludableItems to avoid inplace modifications.

Arguments:

  • other: other excludable items to be copied :type other: ormar.models.excludable.ExcludableItems

Returns:

copy of other :rtype: ormar.models.excludable.ExcludableItems

include_entry_count

1
 | include_entry_count() -> int

Returns count of include items inside

get

1
 | get(model_cls: Type["Model"], alias: str = "") -> Excludable

Return Excludable for given model and alias.

Arguments:

  • model_cls: target model to check :type model_cls: ormar.models.metaclass.ModelMetaclass
  • alias: table alias from relation manager :type alias: str

Returns:

Excludable for given model and alias :rtype: ormar.models.excludable.Excludable

build

1
 | 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: values to be included or excluded :type items: Union[List[str], str, Tuple[str], Set[str], Dict]
  • model_cls: source model from which relations are constructed :type model_cls: ormar.models.metaclass.ModelMetaclass
  • is_exclude: flag if items should be included or excluded :type is_exclude: bool

_set_excludes

1
 | _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: items to include/exclude :type items: set
  • model_name: name of model to construct key :type model_name: str
  • is_exclude: flag if values should be included or excluded :type is_exclude: bool
  • alias: :type alias: str

_traverse_dict

1
 | _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: items to include/exclude :type values: Dict
  • source_model: source model from which relations are constructed :type source_model: ormar.models.metaclass.ModelMetaclass
  • model_cls: model from which current relation is constructed :type model_cls: ormar.models.metaclass.ModelMetaclass
  • is_exclude: flag if values should be included or excluded :type is_exclude: bool
  • related_items: list of names of related fields chain :type related_items: List
  • alias: alias of relation :type alias: str

_traverse_list

1
 | _traverse_list(values: Set[str], model_cls: Type["Model"], is_exclude: bool) -> None

Goes through list of values and construct/update Excludables.

Arguments:

  • values: items to include/exclude :type values: set
  • model_cls: model from which current relation is constructed :type model_cls: ormar.models.metaclass.ModelMetaclass
  • is_exclude: flag if values should be included or excluded :type is_exclude: bool