Skip to content

models.helpers.models

is_field_an_forward_ref

1
is_field_an_forward_ref(field: "BaseField") -> bool

Checks if field is a relation field and whether any of the referenced models are ForwardRefs that needs to be updated before proceeding.

Arguments:

  • field: model field to verify :type field: Type[BaseField]

Returns:

result of the check :rtype: bool

populate_default_options_values

1
populate_default_options_values(new_model: Type["Model"], model_fields: Dict) -> None

Sets all optional Meta values to it's defaults and set model_fields that were already previously extracted.

Here should live all options that are not overwritten/set for all models.

Current options are: * constraints = [] * abstract = False

Arguments:

  • new_model: newly constructed Model :type new_model: Model class
  • model_fields: dict of model fields :type model_fields: Union[Dict[str, type], Dict]

substitue_backend_pool_for_sqlite

1
substitue_backend_pool_for_sqlite(new_model: Type["Model"]) -> None

Recreates Connection pool for sqlite3 with new factory that executes "PRAGMA foreign_keys=1; on initialization to enable foreign keys.

Arguments:

  • new_model: newly declared ormar Model :type new_model: Model class

check_required_meta_parameters

1
check_required_meta_parameters(new_model: Type["Model"]) -> None

Verifies if ormar.Model has database and metadata set.

Recreates Connection pool for sqlite3

Arguments:

  • new_model: newly declared ormar Model :type new_model: Model class

extract_annotations_and_default_vals

1
extract_annotations_and_default_vals(attrs: Dict) -> Tuple[Dict, Dict]

Extracts annotations from class namespace dict and triggers extraction of ormar model_fields.

Arguments:

  • attrs: namespace of the class created :type attrs: Dict

Returns:

namespace of the class updated, dict of extracted model_fields :rtype: Tuple[Dict, Dict]

1
group_related_list(list_: List) -> collections.OrderedDict

Translates the list of related strings into a dictionary. That way nested models are grouped to traverse them in a right order and to avoid repetition.

Sample: ["people__houses", "people__cars__models", "people__cars__colors"] will become: {'people': {'houses': [], 'cars': ['models', 'colors']}}

Result dictionary is sorted by length of the values and by key

Arguments:

  • list_: list of related models used in select related :type list_: List[str]

Returns:

list converted to dictionary to avoid repetition and group nested models :rtype: Dict[str, List]

meta_field_not_set

1
meta_field_not_set(model: Type["Model"], field_name: str) -> bool

Checks if field with given name is already present in model.Meta. Then check if it's set to something truthful (in practice meaning not None, as it's non or ormar Field only).

Arguments:

  • model: newly constructed model :type model: Model class
  • field_name: name of the ormar field :type field_name: str

Returns:

result of the check :rtype: bool