MCPcopy
hub / github.com/ormar-orm/ormar / populate_through_models

Method populate_through_models

ormar/models/newbasemodel.py:707–745  ·  view source on GitHub ↗

Populates through models with values from dict representation. :param model: model to populate through models :type model: Model :param model_dict: dict representation of the model :type model_dict: dict :param include: fields to include :typ

(
        model: "Model",
        model_dict: builtins.dict,
        include: Union[set, builtins.dict],
        exclude: Union[set, builtins.dict],
        relation_map: builtins.dict,
    )

Source from the content-addressed store, hash-verified

705
706 @staticmethod
707 def populate_through_models(
708 model: "Model",
709 model_dict: builtins.dict,
710 include: Union[set, builtins.dict],
711 exclude: Union[set, builtins.dict],
712 relation_map: builtins.dict,
713 ) -> None:
714 """
715 Populates through models with values from dict representation.
716
717 :param model: model to populate through models
718 :type model: Model
719 :param model_dict: dict representation of the model
720 :type model_dict: dict
721 :param include: fields to include
722 :type include: dict
723 :param exclude: fields to exclude
724 :type exclude: dict
725 :param relation_map: map of relations to follow to avoid circular refs
726 :type relation_map: dict
727 :return: None
728 :rtype: None
729 """
730
731 models_to_populate = filter_not_excluded_fields(
732 fields=model.extract_through_names(),
733 include=normalize_to_dict(include),
734 exclude=normalize_to_dict(exclude),
735 )
736 through_fields_to_populate = [
737 model.ormar_config.model_fields[through_model]
738 for through_model in models_to_populate
739 if model.ormar_config.model_fields[through_model].related_name
740 not in relation_map
741 ]
742 for through_field in through_fields_to_populate:
743 through_instance = getattr(model, through_field.name)
744 if through_instance:
745 model_dict[through_field.name] = through_instance.model_dump()
746
747 @staticmethod
748 def _resolve_field_descent( # noqa: CFQ002

Callers 2

Calls 4

normalize_to_dictFunction · 0.90
extract_through_namesMethod · 0.80
model_dumpMethod · 0.80

Tested by

no test coverage detected