django_find.refs module¶
-
django_find.refs.
child_classes
(cls)[source]¶ Returns all models that have a foreign key pointing to cls.
-
django_find.refs.
get_join_for
(vector)[source]¶ Given a vector as returned by get_object_vector_for(), this function returns a list of tuples that explain how to join the models (tables) together on the SQL layer. Each tuple has three elements:
(table_name, left_key, right_key)
In the first tuple of the list, left_key is always None. In the second tuple of the list, right_key is always None. All other tuples required both keys to join them.
Complete example (keep in mind that the connection between Component and Unit is many-to-many, so there’s a helper table here):
get_join_path_for((Device, Component, Unit))
This returns:
[ ('inventory_device', None, None), ('inventory_component', 'device_id', 'inventory_device.metadata_id'), ('inventory_unit_component', 'component_id', 'inventory_component.id'), ('inventory_unit', 'id', 'inventory_unit_component.unit_id') ]
Which means that the following SQL JOIN could be used:
SELECT * FROM inventory_device LEFT JOIN inventory_component ON inventory_component.device_id=inventory_device.metadata_id LEFT JOIN inventory_unit_component ON inventory_unit_component.component_id=inventory_component.id LEFT JOIN inventory_unit ON inventory_unit.id=inventory_unit_component.unit_id
-
django_find.refs.
get_object_vector_for
(cls, search_cls_list, subtype, avoid=None)[source]¶ Like get_object_vector_to(), but returns a single vector that reaches all of the given classes, if it exists. Only searches classes that are subtype of the given class.
-
django_find.refs.
get_object_vector_to
(cls, search_cls, subtype, avoid=None)[source]¶ Returns a list of all possible paths to the given class. Only searches classes that are subtype of the given class.
-
django_find.refs.
get_subclasses
(cls)[source]¶ Recursively finds all subclasses of the current class. Like Python’s __class__.__subclasses__(), but recursive. Returns a list containing all subclasses.
@type cls: object @param cls: A Python class. @rtype: list(object) @return: A list containing all subclasses.
-
django_find.refs.
parent_classes
(cls)[source]¶ Returns all models that are referenced by a foreign key of the given class.
-
django_find.refs.
sort_vectors_by_primary_cls
(vectors, primary_cls)[source]¶ Sort the vectors by the position of the primary class, and the vector length.