MCPcopy
hub / github.com/django/django / _get_path_info

Method _get_path_info

django/db/models/fields/related.py:1942–1971  ·  view source on GitHub ↗

Called by both direct and indirect m2m traversal.

(self, direct=False, filtered_relation=None)

Source from the content-addressed store, hash-verified

1940 return attname, None
1941
1942 def _get_path_info(self, direct=False, filtered_relation=None):
1943 """Called by both direct and indirect m2m traversal."""
1944 int_model = self.remote_field.through
1945 linkfield1 = int_model._meta.get_field(self.m2m_field_name())
1946 linkfield2 = int_model._meta.get_field(self.m2m_reverse_field_name())
1947 if direct:
1948 join1infos = linkfield1.reverse_path_infos
1949 if filtered_relation:
1950 join2infos = linkfield2.get_path_info(filtered_relation)
1951 else:
1952 join2infos = linkfield2.path_infos
1953 else:
1954 join1infos = linkfield2.reverse_path_infos
1955 if filtered_relation:
1956 join2infos = linkfield1.get_path_info(filtered_relation)
1957 else:
1958 join2infos = linkfield1.path_infos
1959 # Get join infos between the last model of join 1 and the first model
1960 # of join 2. Assume the only reason these may differ is due to model
1961 # inheritance.
1962 join1_final = join1infos[-1].to_opts
1963 join2_initial = join2infos[0].from_opts
1964 if join1_final is join2_initial:
1965 intermediate_infos = []
1966 elif issubclass(join1_final.model, join2_initial.model):
1967 intermediate_infos = join1_final.get_path_to_parent(join2_initial.model)
1968 else:
1969 intermediate_infos = join2_initial.get_path_from_parent(join1_final.model)
1970
1971 return [*join1infos, *intermediate_infos, *join2infos]
1972
1973 def get_path_info(self, filtered_relation=None):
1974 return self._get_path_info(direct=True, filtered_relation=filtered_relation)

Callers 2

get_path_infoMethod · 0.95
get_reverse_path_infoMethod · 0.95

Calls 4

get_path_to_parentMethod · 0.80
get_path_from_parentMethod · 0.80
get_fieldMethod · 0.45
get_path_infoMethod · 0.45

Tested by

no test coverage detected