MCPcopy
hub / github.com/django/django / get_path_from_parent

Method get_path_from_parent

django/db/models/options.py:786–806  ·  view source on GitHub ↗

Return a list of PathInfos containing the path from the parent model to the current model, or an empty list if parent is not a parent of the current model.

(self, parent)

Source from the content-addressed store, hash-verified

784 return path
785
786 def get_path_from_parent(self, parent):
787 """
788 Return a list of PathInfos containing the path from the parent
789 model to the current model, or an empty list if parent is not a
790 parent of the current model.
791 """
792 if self.model is parent:
793 return []
794 model = self.concrete_model
795 # Get a reversed base chain including both the current and parent
796 # models.
797 chain = model._meta.get_base_chain(parent)
798 chain.reverse()
799 chain.append(model)
800 # Construct a list of the PathInfos between models in chain.
801 path = []
802 for i, ancestor in enumerate(chain[:-1]):
803 child = chain[i + 1]
804 link = child._meta.get_ancestor_link(ancestor)
805 path.extend(link.reverse_path_infos)
806 return path
807
808 def _populate_directed_relation_graph(self):
809 """

Callers 1

_get_path_infoMethod · 0.80

Calls 5

get_base_chainMethod · 0.80
get_ancestor_linkMethod · 0.80
extendMethod · 0.80
reverseMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected