Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2 

3This is a simplistic implementation of tree-like functionality using only a ``parent`` field that refers to ``self``. 

4It performs well for a relatively small number of records. For thousands records, you may wish to review the following 

5resources: 

6 

7- `MPTT`_ 

8- `Treebeard`_ 

9 

10.. _MPTT: https://django-mptt.readthedocs.io/en/latest/index.html 

11.. _Treebeard: http://django-treebeard.readthedocs.io/en/latest/index.html 

12 

13Graphing 

14-------- 

15 

16Parent-tree provides a utility for creating a visual graph of a given record and all of its children. 

17 

18.. important:: 

19 The ``anytree`` package is required to utilize this functionality. 

20 

21The :py:class:`superdjango.db.parent.utils.Diagram` class may be used to create an image. Suppose you have an HR tool 

22and you want to present the structure of an organization: 

23 

24.. code-block:: python 

25 

26 from django.conf import settings 

27 import os 

28 from superdjango.db.parent.utils import Diagram 

29 from hr.organizations.models import Organization 

30 

31 # Load the graphing utility. 

32 org = Organization.objects.get(pk=1) 

33 diagram = Diagram(org) 

34 

35 # Output the image. 

36 graph = diagram.to_graph() 

37 path = os.path.join(settings.MEDIA_ROOT, "hr", "orgs", "%s.jpg" % org.pk) 

38 graph.to_picture(path) 

39 

40""" 

41__author__ = "Shawn Davis <shawn@superdjango.com>" 

42__maintainer__ = "Shawn Davis <shawn@superdjango.com>" 

43__version__ = "0.7.0-x"