Skip to content

models.mixins.relation_mixin

RelationMixin Objects

1
class RelationMixin()

Used to return relation fields/names etc. from given model

extract_db_own_fields

1
2
 | @classmethod
 | extract_db_own_fields(cls) -> Set

Returns only fields that are stored in the own database table, exclude all related fields.

Returns:

set of model fields with relation fields excluded :rtype: Set

1
2
 | @classmethod
 | extract_related_fields(cls) -> List["ForeignKeyField"]

Returns List of ormar Fields for all relations declared on a model. List is cached in cls._related_fields for quicker access.

Returns:

list of related fields :rtype: List

extract_through_names

1
2
 | @classmethod
 | extract_through_names(cls) -> Set[str]

Extracts related fields through names which are shortcuts to through models.

Returns:

set of related through fields names :rtype: Set

1
2
 | @classmethod
 | extract_related_names(cls) -> Set[str]

Returns List of fields names for all relations declared on a model. List is cached in cls._related_names for quicker access.

Returns:

set of related fields names :rtype: Set

1
2
 | @classmethod
 | _extract_db_related_names(cls) -> Set

Returns only fields that are stored in the own database table, exclude related fields that are not stored as foreign keys on given model.

Returns:

set of model fields with non fk relation fields excluded :rtype: Set

1
2
 | @classmethod
 | _iterate_related_models(cls, node_list: NodeList = None, parsed_map: Dict = None, source_relation: str = None, recurrent: bool = False) -> List[str]

Iterates related models recursively to extract relation strings of nested not visited models.

Returns:

list of relation strings to be passed to select_related :rtype: List[str]

_get_final_relations

1
2
 | @staticmethod
 | _get_final_relations(processed_relations: List, source_relation: Optional[str]) -> List[str]

Helper method to prefix nested relation strings with current source relation

Arguments:

  • processed_relations: list of already processed relation str :type processed_relations: List[str]
  • source_relation: name of the current relation :type source_relation: str

Returns:

list of relation strings to be passed to select_related :rtype: List[str]