Gustavo Picon is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againdjango-treebeard / docs / index.html
- Tag
- 1.5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>treebeard — Efficient tree model implementations for Django — django-treebeard v1.5 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '1.5',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="django-treebeard v1.5 documentation" href="" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="modindex.html" title="Global Module Index"
accesskey="M">modules</a> |</li>
<li><a href="">django-treebeard v1.5 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-treebeard.models">
<h1><tt class="xref docutils literal"><span class="pre">treebeard</span></tt> — Efficient tree model implementations for Django<a class="headerlink" href="#module-treebeard.models" title="Permalink to this headline">¶</a></h1>
<div class="section" id="treebeard">
<h2>treebeard<a class="headerlink" href="#treebeard" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">synopsys:</th><td class="field-body">Efficient Tree implementations for Django 1.0+</td>
</tr>
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">2008-2009 by <a class="reference external" href="http://tabo.pe">Gustavo Picon</a></td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body">Apache License 2.0</td>
</tr>
<tr class="field"><th class="field-name">version:</th><td class="field-body">1.5</td>
</tr>
<tr class="field"><th class="field-name">url:</th><td class="field-body"><a class="reference external" href="http://code.tabo.pe/django-treebeard/">http://code.tabo.pe/django-treebeard/</a></td>
</tr>
<tr class="field"><th class="field-name">documentation:</th><td class="field-body"><a class="reference external" href="http://docs.tabo.pe/django-treebeard/1.5/">treebeard-docs</a></td>
</tr>
<tr class="field"><th class="field-name">examples:</th><td class="field-body"><a class="reference external" href="http://django.tabo.pe/tbexample/">treebeard-examples</a>
(<a class="reference external" href="http://code.tabo.pe/django-treebeard/src/1.5/tbexample/">source</a>)</td>
</tr>
<tr class="field"><th class="field-name">tests:</th><td class="field-body"><a class="reference external" href="http://code.tabo.pe/django-treebeard/src/1.5/treebeard/tests.py">treebeard-tests</a></td>
</tr>
<tr class="field"><th class="field-name">benchmarks:</th><td class="field-body"><a class="reference external" href="#module-tbbench">treebeard-benchmarks</a></td>
</tr>
</tbody>
</table>
<p><tt class="docutils literal"><span class="pre">django-treebeard</span></tt> is a library that implements efficient tree
implementations for the <a class="reference external" href="http://www.djangoproject.com/">Django Web Framework 1.0+</a>. It includes 3 different tree
implementations: Adjacency List, Materialized Path and Nested Sets. Each
one has it’s own strength and weaknesses (see
<a class="reference external" href="#module-tbbench">Benchmarks</a>) but share the same
API, so it’s easy to switch between implementations.</p>
<p><tt class="docutils literal"><span class="pre">django-treebeard</span></tt> uses <a class="reference external" href="http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes">Django Model Inheritance with abstract classes</a>
to let you define your own models. To use <tt class="docutils literal"><span class="pre">django-treebeard</span></tt>:</p>
<blockquote>
<ol class="arabic simple">
<li>Download a release from the <a class="reference external" href="http://code.tabo.pe/django-treebeard/downloads/">treebeard download page</a> or get a
development version from the <a class="reference external" href="http://code.tabo.pe/django-treebeard/src/">treebeard mercurial repository</a>.</li>
<li>Run <strong>python setup.py install</strong></li>
<li>Add <tt class="docutils literal"><span class="pre">'treebeard'</span></tt> to the <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt> section in your django
settings file.</li>
<li>Create a new model that inherits from one of <tt class="docutils literal"><span class="pre">django-treebeard</span></tt>‘s
abstract tree models: <a title="treebeard.mp_tree.MP_Node" class="reference internal" href="#treebeard.mp_tree.MP_Node"><tt class="xref docutils literal"><span class="pre">mp_tree.MP_Node</span></tt></a> (materialized path),
<a title="treebeard.ns_tree.NS_Node" class="reference internal" href="#treebeard.ns_tree.NS_Node"><tt class="xref docutils literal"><span class="pre">ns_tree.NS_Node</span></tt></a> (nested sets) or <a title="treebeard.al_tree.AL_Node" class="reference internal" href="#treebeard.al_tree.AL_Node"><tt class="xref docutils literal"><span class="pre">al_tree.AL_Node</span></tt></a>
(adjacency list).</li>
<li>Run <strong>python manage.py syncdb</strong></li>
</ol>
</blockquote>
<p>Read the <a title="treebeard.models.Node" class="reference internal" href="#treebeard.models.Node"><tt class="xref docutils literal"><span class="pre">models.Node</span></tt></a> API reference for detailed info.</p>
</div>
<div class="section" id="treebeard-models">
<h2>treebeard.models<a class="headerlink" href="#treebeard-models" title="Permalink to this headline">¶</a></h2>
<p>Django models.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">2008-2009 by Gustavo Picon</td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body">Apache License 2.0</td>
</tr>
</tbody>
</table>
<dl class="class">
<dt id="treebeard.models.Node">
<em class="property">class </em><tt class="descclassname">treebeard.models.</tt><tt class="descname">Node</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.models.Node" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <tt class="xref docutils literal"><span class="pre">django.db.models.base.Model</span></tt></p>
<p>Node class.</p>
<p>This is the base class that defines the API of all tree models in this
library:</p>
<blockquote>
<ul class="simple">
<li><tt class="xref docutils literal"><span class="pre">mp_tree.MP_Node</span></tt> (materialized path)</li>
<li><tt class="xref docutils literal"><span class="pre">ns_tree.NS_Node</span></tt> (nested sets)</li>
<li><tt class="xref docutils literal"><span class="pre">al_tree.AL_Node</span></tt> (adjacency list)</li>
</ul>
</blockquote>
<dl class="classmethod">
<dt id="treebeard.models.Node.add_root">
<em class="property">classmethod </em><tt class="descname">add_root</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.add_root" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a root node to the tree. The new root node will be the new
rightmost root node. If you want to insert a root node at a specific
position, use <a title="treebeard.models.Node.add_sibling" class="reference internal" href="#treebeard.models.Node.add_sibling"><tt class="xref docutils literal"><span class="pre">add_sibling()</span></tt></a> in an already existing root node
instead.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>**kwargs</em> – object creation data that will be passed to the
inherited Node model</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">the created node object. It will be save()d by this method.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">MyNode</span><span class="o">.</span><span class="n">add_root</span><span class="p">(</span><span class="n">numval</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">strval</span><span class="o">=</span><span class="s">'abcd'</span><span class="p">)</span>
<span class="n">MyNode</span><span class="o">.</span><span class="n">add_root</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s">'numval'</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span> <span class="s">'strval'</span><span class="p">:</span><span class="s">'abcd'</span><span class="p">})</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.add_child">
<tt class="descname">add_child</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.add_child" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a child to the node. The new node will be the new rightmost
child. If you want to insert a node at a specific position,
use the <a title="treebeard.models.Node.add_sibling" class="reference internal" href="#treebeard.models.Node.add_sibling"><tt class="xref docutils literal"><span class="pre">add_sibling()</span></tt></a> method of an already existing
child node instead.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>**kwargs</em> – Object creation data that will be passed to the inherited Node
model</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The created node object. It will be save()d by this method.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="n">numval</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">strval</span><span class="o">=</span><span class="s">'abcd'</span><span class="p">)</span>
<span class="n">node</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s">'numval'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s">'strval'</span><span class="p">:</span> <span class="s">'abcd'</span><span class="p">})</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.add_sibling">
<tt class="descname">add_sibling</tt><big>(</big><em>pos=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.add_sibling" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a new node as a sibling to the current node object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>pos</em> – <p>The position, relative to the current node object, where the
new node will be inserted, can be one of:</p>
<ul>
<li><tt class="docutils literal"><span class="pre">first-sibling</span></tt>: the new node will be the new leftmost sibling</li>
<li><tt class="docutils literal"><span class="pre">left</span></tt>: the new node will take the node’s place, which will be
moved to the right 1 position</li>
<li><tt class="docutils literal"><span class="pre">right</span></tt>: the new node will be inserted at the right of the node</li>
<li><tt class="docutils literal"><span class="pre">last-sibling</span></tt>: the new node will be the new rightmost sibling</li>
<li><tt class="docutils literal"><span class="pre">sorted-sibling</span></tt>: the new node will be at the right position
according to the value of node_order_by</li>
</ul>
</li>
<li><em>**kwargs</em> – Object creation data that will be passed to the inherited
Node model</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The created node object. It will be saved by this method.</p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">Raises InvalidPosition:</th></tr>
<tr><td> </td><td class="field-body"><p class="first">when passing an invalid <tt class="docutils literal"><span class="pre">pos</span></tt> parm</p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">Raises InvalidPosition:</th></tr>
<tr><td> </td><td class="field-body"><p class="first">when <tt class="xref docutils literal"><span class="pre">node_order_by</span></tt> is enabled and the
<tt class="docutils literal"><span class="pre">pos</span></tt> parm wasn’t <tt class="docutils literal"><span class="pre">sorted-sibling</span></tt></p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">Raises MissingNodeOrderBy:</th></tr>
<tr><td> </td><td class="field-body"><p class="first last">when passing <tt class="docutils literal"><span class="pre">sorted-sibling</span></tt> as <tt class="docutils literal"><span class="pre">pos</span></tt>
and the <tt class="xref docutils literal"><span class="pre">node_order_by</span></tt> attribute is missing</p>
</td>
</tr>
</tbody>
</table>
<p>Examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">add_sibling</span><span class="p">(</span><span class="s">'sorted-sibling'</span><span class="p">,</span> <span class="n">numval</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">strval</span><span class="o">=</span><span class="s">'abc'</span><span class="p">)</span>
<span class="n">node</span><span class="o">.</span><span class="n">add_sibling</span><span class="p">(</span><span class="s">'sorted-sibling'</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s">'numval'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s">'strval'</span><span class="p">:</span> <span class="s">'abc'</span><span class="p">})</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.delete">
<tt class="descname">delete</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.delete" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes a node and all it’s descendants.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Call our queryset’s delete to handle children removal. Subclasses
will handle extra maintenance.</p>
</div>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.models.Node.get_tree">
<em class="property">classmethod </em><tt class="descname">get_tree</tt><big>(</big><em>parent=None</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_tree" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">A list of nodes ordered as DFS, including the parent. If
no parent is given, the entire tree is returned.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_depth">
<tt class="descname">get_depth</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_depth" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">the depth (level) of the node</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_depth</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_ancestors">
<tt class="descname">get_ancestors</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_ancestors" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">A queryset containing the current node object’s ancestors,
starting by the root node and descending to the parent.
(some subclasses may return a list)</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_ancestors</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_children">
<tt class="descname">get_children</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_children" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">A queryset of all the node’s children</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_children</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_children_count">
<tt class="descname">get_children_count</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_children_count" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The number of the node’s children</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_children_count</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_descendants">
<tt class="descname">get_descendants</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_descendants" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">A queryset of all the node’s descendants, doesn’t
include the node itself (some subclasses may return a list).</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_descendants</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_descendant_count">
<tt class="descname">get_descendant_count</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_descendant_count" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">the number of descendants of a node.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_descendant_count</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_first_child">
<tt class="descname">get_first_child</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_first_child" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The leftmost node’s child, or None if it has no children.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_first_child</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_last_child">
<tt class="descname">get_last_child</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_last_child" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The rightmost node’s child, or None if it has no children.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_last_child</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_first_sibling">
<tt class="descname">get_first_sibling</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_first_sibling" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The leftmost node’s sibling, can return the node itself if it
was the leftmost sibling.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_first_sibling</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_last_sibling">
<tt class="descname">get_last_sibling</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_last_sibling" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The rightmost node’s sibling, can return the node itself if
it was the rightmost sibling.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_last_sibling</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_prev_sibling">
<tt class="descname">get_prev_sibling</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_prev_sibling" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The previous node’s sibling, or None if it was the leftmost
sibling.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_prev_sibling</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_next_sibling">
<tt class="descname">get_next_sibling</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_next_sibling" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The next node’s sibling, or None if it was the rightmost
sibling.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_next_sibling</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_parent">
<tt class="descname">get_parent</tt><big>(</big><em>update=False</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_parent" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">the parent node of the current node object.
Caches the result in the object itself to help in loops.</td>
</tr>
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>update</em> – Updates de cached value.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_parent</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_root">
<tt class="descname">get_root</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_root" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">the root node for the current node object.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_root</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.get_siblings">
<tt class="descname">get_siblings</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_siblings" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">A queryset of all the node’s siblings, including the node
itself.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">get_siblings</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.is_child_of">
<tt class="descname">is_child_of</tt><big>(</big><em>node</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.is_child_of" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="xref docutils literal"><span class="pre">True</span></tt> if the node is a child of another node given as an
argument, else, returns <tt class="xref docutils literal"><span class="pre">False</span></tt></td>
</tr>
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>node</em> – The node that will be checked as a parent</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">is_child_of</span><span class="p">(</span><span class="n">node2</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.is_descendant_of">
<tt class="descname">is_descendant_of</tt><big>(</big><em>node</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.is_descendant_of" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="xref docutils literal"><span class="pre">True</span></tt> if the node if a descendant of another node given
as an argument, else, returns <tt class="xref docutils literal"><span class="pre">False</span></tt></td>
</tr>
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>node</em> – The node that will be checked as an ancestor</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">is_descendant_of</span><span class="p">(</span><span class="n">node2</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.is_sibling_of">
<tt class="descname">is_sibling_of</tt><big>(</big><em>node</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.is_sibling_of" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="xref docutils literal"><span class="pre">True</span></tt> if the node if a sibling of another node given as an
argument, else, returns <tt class="xref docutils literal"><span class="pre">False</span></tt></td>
</tr>
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>node</em> – The node that will be checked as a sibling</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">is_sibling_of</span><span class="p">(</span><span class="n">node2</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.is_root">
<tt class="descname">is_root</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.is_root" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">True if the node is a root node (else, returns False)</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">is_root</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.is_leaf">
<tt class="descname">is_leaf</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.is_leaf" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">True if the node is a leaf node (else, returns False)</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">is_leaf</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.move">
<tt class="descname">move</tt><big>(</big><em>target</em>, <em>pos=None</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.move" title="Permalink to this definition">¶</a></dt>
<dd><p>Moves the current node and all it’s descendants to a new position
relative to another node.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The node can be moved under another root node.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>target</em> – The node that will be used as a relative child/sibling when moving</li>
<li><em>pos</em> – <p>The position, relative to the target node, where the
current node object will be moved to, can be one of:</p>
<ul>
<li><tt class="docutils literal"><span class="pre">first-child</span></tt>: the node will be the new leftmost child of the
<tt class="docutils literal"><span class="pre">target</span></tt> node</li>
<li><tt class="docutils literal"><span class="pre">last-child</span></tt>: the node will be the new rightmost child of the
<tt class="docutils literal"><span class="pre">target</span></tt> node</li>
<li><tt class="docutils literal"><span class="pre">sorted-child</span></tt>: the new node will be moved as a child of the
<tt class="docutils literal"><span class="pre">target</span></tt> node according to the value of <tt class="xref docutils literal"><span class="pre">node_order_by</span></tt></li>
<li><tt class="docutils literal"><span class="pre">first-sibling</span></tt>: the node will be the new leftmost sibling of
the <tt class="docutils literal"><span class="pre">target</span></tt> node</li>
<li><tt class="docutils literal"><span class="pre">left</span></tt>: the node will take the <tt class="docutils literal"><span class="pre">target</span></tt> node’s place, which
will be moved to the right 1 position</li>
<li><tt class="docutils literal"><span class="pre">right</span></tt>: the node will be moved to the right of the <tt class="docutils literal"><span class="pre">target</span></tt>
node</li>
<li><tt class="docutils literal"><span class="pre">last-sibling</span></tt>: the node will be the new rightmost sibling of
the <tt class="docutils literal"><span class="pre">target</span></tt> node</li>
<li><tt class="docutils literal"><span class="pre">sorted-sibling</span></tt>: the new node will be moved as a sibling of
the <tt class="docutils literal"><span class="pre">target</span></tt> node according to the value of
<tt class="xref docutils literal"><span class="pre">node_order_by</span></tt></li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If no <tt class="docutils literal"><span class="pre">pos</span></tt> is given the library will use
<tt class="docutils literal"><span class="pre">last-sibling</span></tt>, or <tt class="docutils literal"><span class="pre">sorted-sibling</span></tt> if
<tt class="xref docutils literal"><span class="pre">node_order_by</span></tt> is enabled.</p>
</div>
</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">None</p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">Raises InvalidPosition:</th></tr>
<tr><td> </td><td class="field-body"><p class="first">when passing an invalid <tt class="docutils literal"><span class="pre">pos</span></tt> parm</p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">Raises InvalidPosition:</th></tr>
<tr><td> </td><td class="field-body"><p class="first">when <tt class="xref docutils literal"><span class="pre">node_order_by</span></tt> is enabled and the
<tt class="docutils literal"><span class="pre">pos</span></tt> parm wasn’t <tt class="docutils literal"><span class="pre">sorted-sibling</span></tt> or <tt class="docutils literal"><span class="pre">sorted-child</span></tt></p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">Raises InvalidMoveToDescendant:</th></tr>
<tr><td> </td><td class="field-body"><p class="first">when trying to move a node to one of
it’s own descendants</p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">Raises PathOverflow:</th></tr>
<tr><td> </td><td class="field-body"><p class="first">when the library can’t make room for the
node’s new position</p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">Raises MissingNodeOrderBy:</th></tr>
<tr><td> </td><td class="field-body"><p class="first last">when passing <tt class="docutils literal"><span class="pre">sorted-sibling</span></tt> or
<tt class="docutils literal"><span class="pre">sorted-child</span></tt> as <tt class="docutils literal"><span class="pre">pos</span></tt> and the <tt class="xref docutils literal"><span class="pre">node_order_by</span></tt>
attribute is missing</p>
</td>
</tr>
</tbody>
</table>
<p>Examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">node2</span><span class="p">,</span> <span class="s">'sorted-child'</span><span class="p">)</span>
<span class="n">node</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">node2</span><span class="p">,</span> <span class="s">'prev-sibling'</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="treebeard.models.Node.save">
<tt class="descname">save</tt><big>(</big><em>force_insert=False</em>, <em>force_update=False</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.save" title="Permalink to this definition">¶</a></dt>
<dd><p>Saves the current instance. Override this in a subclass if you want to
control the saving process.</p>
<p>The ‘force_insert’ and ‘force_update’ parameters can be used to insist
that the “save” must be an SQL insert or update (or equivalent for
non-SQL backends), respectively. Normally, they should not be set.</p>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.models.Node.get_first_root_node">
<em class="property">classmethod </em><tt class="descname">get_first_root_node</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_first_root_node" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The first root node in the tree or <tt class="xref docutils literal"><span class="pre">None</span></tt> if it is empty</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">MyNodeModel</span><span class="o">.</span><span class="n">get_first_root_node</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.models.Node.get_last_root_node">
<em class="property">classmethod </em><tt class="descname">get_last_root_node</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_last_root_node" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">The last root node in the tree or <tt class="xref docutils literal"><span class="pre">None</span></tt> if it is empty</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">MyNodeModel</span><span class="o">.</span><span class="n">get_last_root_node</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.models.Node.get_root_nodes">
<em class="property">classmethod </em><tt class="descname">get_root_nodes</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_root_nodes" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">A queryset containing the root nodes in the tree.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">MyNodeModel</span><span class="o">.</span><span class="n">get_root_nodes</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.models.Node.load_bulk">
<em class="property">classmethod </em><tt class="descname">load_bulk</tt><big>(</big><em>bulk_data</em>, <em>parent=None</em>, <em>keep_ids=False</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.load_bulk" title="Permalink to this definition">¶</a></dt>
<dd><p>Loads a list/dictionary structure to the tree.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>bulk_data</em> – <p>The data that will be loaded, the structure is a list of
dictionaries with 2 keys:</p>
<ul>
<li><tt class="docutils literal"><span class="pre">data</span></tt>: will store arguments that will be passed for object
creation, and</li>
<li><tt class="docutils literal"><span class="pre">children</span></tt>: a list of dictionaries, each one has it’s own
<tt class="docutils literal"><span class="pre">data</span></tt> and <tt class="docutils literal"><span class="pre">children</span></tt> keys (a recursive structure)</li>
</ul>
</li>
<li><em>parent</em> – The node that will receive the structure as children, if not
specified the first level of the structure will be loaded as root
nodes</li>
<li><em>keep_ids</em> – If enabled, lads the nodes with the same id that are given in the
structure. Will error if there are nodes without id info or if the
ids are already used.</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A list of the added node ids.</p>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Any internal data that you may have stored in your
nodes’ data (<tt class="xref docutils literal"><span class="pre">path</span></tt>, <tt class="xref docutils literal"><span class="pre">depth</span></tt>) will be
ignored.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If your node model has <tt class="xref docutils literal"><span class="pre">node_order_by</span></tt> enabled, it will
take precedence over the order in the structure.</p>
</div>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">data</span> <span class="o">=</span> <span class="p">[{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'1'</span><span class="p">}},</span>
<span class="p">{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'2'</span><span class="p">},</span> <span class="s">'children'</span><span class="p">:[</span>
<span class="p">{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'21'</span><span class="p">}},</span>
<span class="p">{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'22'</span><span class="p">}},</span>
<span class="p">{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'23'</span><span class="p">},</span> <span class="s">'children'</span><span class="p">:[</span>
<span class="p">{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'231'</span><span class="p">}},</span>
<span class="p">]},</span>
<span class="p">{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'24'</span><span class="p">}},</span>
<span class="p">]},</span>
<span class="p">{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'3'</span><span class="p">}},</span>
<span class="p">{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'4'</span><span class="p">},</span> <span class="s">'children'</span><span class="p">:[</span>
<span class="p">{</span><span class="s">'data'</span><span class="p">:{</span><span class="s">'desc'</span><span class="p">:</span><span class="s">'41'</span><span class="p">}},</span>
<span class="p">]},</span>
<span class="p">]</span>
<span class="c"># parent = None</span>
<span class="n">MyNodeModel</span><span class="o">.</span><span class="n">load_data</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
</pre></div>
</div>
<p>Will create:</p>
<blockquote>
<ul class="simple">
<li>1</li>
<li>2<ul>
<li>21</li>
<li>22</li>
<li>23<ul>
<li>231</li>
</ul>
</li>
<li>24</li>
</ul>
</li>
<li>3</li>
<li>4<ul>
<li>41</li>
</ul>
</li>
</ul>
</blockquote>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.models.Node.dump_bulk">
<em class="property">classmethod </em><tt class="descname">dump_bulk</tt><big>(</big><em>parent=None</em>, <em>keep_ids=True</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.dump_bulk" title="Permalink to this definition">¶</a></dt>
<dd><p>Dumps a tree branch to a python data structure.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>parent</em> – The node whose descendants will be dumped. The node itself will be
included in the dump. If not given, the entire tree will be dumped.</li>
<li><em>keep_ids</em> – Stores the id value (primary key) of every node. Enabled by
default.</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A python data structure, describen with detail in
<a title="treebeard.models.Node.load_bulk" class="reference internal" href="#treebeard.models.Node.load_bulk"><tt class="xref docutils literal"><span class="pre">load_bulk()</span></tt></a></p>
</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">tree</span> <span class="o">=</span> <span class="n">MyNodeModel</span><span class="o">.</span><span class="n">dump_bulk</span><span class="p">()</span>
<span class="n">branch</span> <span class="o">=</span> <span class="n">MyNodeModel</span><span class="o">.</span><span class="n">dump_bulk</span><span class="p">(</span><span class="n">node_obj</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.models.Node.find_problems">
<em class="property">classmethod </em><tt class="descname">find_problems</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.find_problems" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks for problems in the tree structure.</p>
<p>Read the documentation of this method on every tree class for details.</p>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.models.Node.fix_tree">
<em class="property">classmethod </em><tt class="descname">fix_tree</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.models.Node.fix_tree" title="Permalink to this definition">¶</a></dt>
<dd><p>Solves some problems that can appear when transactions are not used and
a piece of code breaks, leaving the tree in an inconsistent state.</p>
<p>Read the documentation of this method on every tree class for details.</p>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.models.Node.get_descendants_group_count">
<em class="property">classmethod </em><tt class="descname">get_descendants_group_count</tt><big>(</big><em>parent=None</em><big>)</big><a class="headerlink" href="#treebeard.models.Node.get_descendants_group_count" title="Permalink to this definition">¶</a></dt>
<dd><p>Helper for a very common case: get a group of siblings and the number
of <em>descendants</em> (not only children) in every sibling.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>parent</em> – The parent of the siblings to return. If no parent is given, the
root nodes will be returned.</td>
</tr>
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">A <cite>list</cite> (<strong>NOT</strong> a Queryset) of node objects with an extra
attribute: <cite>descendants_count</cite>.</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># get a list of the root nodes</span>
<span class="n">root_nodes</span> <span class="o">=</span> <span class="n">MyModel</span><span class="o">.</span><span class="n">get_descendants_group_count</span><span class="p">()</span>
<span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">root_nodes</span><span class="p">:</span>
<span class="k">print</span> <span class="s">'</span><span class="si">%s</span><span class="s"> by </span><span class="si">%s</span><span class="s"> (</span><span class="si">%d</span><span class="s"> replies)'</span> <span class="o">%</span> <span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">comment</span><span class="p">,</span> <span class="n">node</span><span class="o">.</span><span class="n">author</span><span class="p">,</span>
<span class="n">node</span><span class="o">.</span><span class="n">descendants_count</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
</dd></dl>
</div>
</div>
<div class="section" id="module-treebeard.mp_tree">
<h1><tt class="xref docutils literal"><span class="pre">treebeard.mp_tree</span></tt> — Materialized Path tree<a class="headerlink" href="#module-treebeard.mp_tree" title="Permalink to this headline">¶</a></h1>
<div class="section" id="treebeard-mp-tree">
<h2>treebeard.mp_tree<a class="headerlink" href="#treebeard-mp-tree" title="Permalink to this headline">¶</a></h2>
<p>Materialized Path Tree.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">2008-2009 by Gustavo Picon</td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body">Apache License 2.0</td>
</tr>
</tbody>
</table>
<p>This is an efficient implementation of Materialized Path
trees for Django 1.0+, as described by <a class="reference external" href="http://vadimtropashko.wordpress.com/">Vadim Tropashko</a> in <a class="reference external" href="http://www.rampant-books.com/book_2006_1_sql_coding_styles.htm">SQL Design
Patterns</a>. Materialized Path is probably the fastest way of working with
trees in SQL without the need of extra work in the database, like Oracle’s
<tt class="docutils literal"><span class="pre">CONNECT</span> <span class="pre">BY</span></tt> or sprocs and triggers for nested intervals.</p>
<p>In a materialized path approach, every node in the tree will have a
<a title="treebeard.mp_tree.MP_Node.path" class="reference internal" href="#treebeard.mp_tree.MP_Node.path"><tt class="xref docutils literal"><span class="pre">path</span></tt></a> attribute, where the full path from the root
to the node will be stored. This has the advantage of needing very simple
and fast queries, at the risk of inconsistency because of the
denormalization of <tt class="docutils literal"><span class="pre">parent</span></tt>/<tt class="docutils literal"><span class="pre">child</span></tt> foreign keys. This can be prevented
with transactions.</p>
<p><tt class="docutils literal"><span class="pre">django-treebeard</span></tt> uses a particular approach: every step in the path has
a fixed width and has no separators. This makes queries predictable and
faster at the cost of using more characters to store a step. To address
this problem, every step number is encoded.</p>
<p>Also, two extra fields are stored in every node:
<a title="treebeard.mp_tree.MP_Node.depth" class="reference internal" href="#treebeard.mp_tree.MP_Node.depth"><tt class="xref docutils literal"><span class="pre">depth</span></tt></a> and <a title="treebeard.mp_tree.MP_Node.numchild" class="reference internal" href="#treebeard.mp_tree.MP_Node.numchild"><tt class="xref docutils literal"><span class="pre">numchild</span></tt></a>.
This makes the read operations faster, at the cost of a little more
maintenance on tree updates/inserts/deletes. Don’t worry, even with these
extra steps, materialized path is more efficient than other approaches.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The materialized path approach makes heavy use of <tt class="docutils literal"><span class="pre">LIKE</span></tt> in your
database, with clauses like <tt class="docutils literal"><span class="pre">WHERE</span> <span class="pre">path</span> <span class="pre">LIKE</span> <span class="pre">'002003%'</span></tt>. If you think
that <tt class="docutils literal"><span class="pre">LIKE</span></tt> is too slow, you’re right, but in this case the
<a title="treebeard.mp_tree.MP_Node.path" class="reference internal" href="#treebeard.mp_tree.MP_Node.path"><tt class="xref docutils literal"><span class="pre">path</span></tt></a> field is indexed in the database, and all
<tt class="docutils literal"><span class="pre">LIKE</span></tt> clauses that don’t <strong>start</strong> with a <tt class="docutils literal"><span class="pre">%</span></tt> character will use
the index. This is what makes the materialized path approach so fast.</p>
</div>
<dl class="class">
<dt id="treebeard.mp_tree.MP_Node">
<em class="property">class </em><tt class="descclassname">treebeard.mp_tree.</tt><tt class="descname">MP_Node</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.mp_tree.MP_Node" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="treebeard.models.Node" class="reference internal" href="#treebeard.models.Node"><tt class="xref docutils literal"><span class="pre">treebeard.models.Node</span></tt></a></p>
<p>Abstract model to create your own Materialized Path Trees.</p>
<dl class="attribute">
<dt id="treebeard.mp_tree.MP_Node.steplen">
<tt class="descname">steplen</tt><a class="headerlink" href="#treebeard.mp_tree.MP_Node.steplen" title="Permalink to this definition">¶</a></dt>
<dd>Attribute that defines the length of each step in the <a title="treebeard.mp_tree.MP_Node.path" class="reference internal" href="#treebeard.mp_tree.MP_Node.path"><tt class="xref docutils literal"><span class="pre">path</span></tt></a> of
a node. The default value of <em>4</em> allows a maximum of
<em>1679615</em> children per node. Increase this value if you plan to store
large trees (a <tt class="docutils literal"><span class="pre">steplen</span></tt> of <em>5</em> allows more than <em>60M</em> children per
node). Note that increasing this value, while increasing the number of
children per node, will decrease the max <a title="treebeard.mp_tree.MP_Node.depth" class="reference internal" href="#treebeard.mp_tree.MP_Node.depth"><tt class="xref docutils literal"><span class="pre">depth</span></tt></a> of the tree (by
default: <em>63</em>). To increase the max <a title="treebeard.mp_tree.MP_Node.depth" class="reference internal" href="#treebeard.mp_tree.MP_Node.depth"><tt class="xref docutils literal"><span class="pre">depth</span></tt></a>, increase the
max_length attribute of the <a title="treebeard.mp_tree.MP_Node.path" class="reference internal" href="#treebeard.mp_tree.MP_Node.path"><tt class="xref docutils literal"><span class="pre">path</span></tt></a> field in your model.</dd></dl>
<dl class="attribute">
<dt id="treebeard.mp_tree.MP_Node.alphabet">
<tt class="descname">alphabet</tt><a class="headerlink" href="#treebeard.mp_tree.MP_Node.alphabet" title="Permalink to this definition">¶</a></dt>
<dd><p>Attribute: the alphabet that will be used in base conversions
when encoding the path steps into strings. The default value,
<tt class="docutils literal"><span class="pre">0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ</span></tt> is the most optimal possible
value that is portable between the supported databases (which means:
their default collation will order the <a title="treebeard.mp_tree.MP_Node.path" class="reference internal" href="#treebeard.mp_tree.MP_Node.path"><tt class="xref docutils literal"><span class="pre">path</span></tt></a> field correctly).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>In case you know what you are doing, there is a test that is
disabled by default that can tell you the optimal default alphabet
in your enviroment. To run the test you must enable the
<span class="target" id="index-0"></span><strong class="xref">TREEBEARD_TEST_ALPHABET</strong> enviroment variable:</p>
<div class="highlight-python"><pre>$ TREEBEARD_TEST_ALPHABET=1 python manage.py test treebeard.TestTreeAlphabet</pre>
</div>
<p>On my Ubuntu 8.04.1 system, these are the optimal values for the three
supported databases in their <em>default</em> configuration:</p>
<blockquote class="last">
<table border="1" class="docutils">
<colgroup>
<col width="21%" />
<col width="79%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Database</th>
<th class="head">Optimal Alphabet</th>
</tr>
</thead>
<tbody valign="top">
<tr><td>MySQL 5.0.51</td>
<td>0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ</td>
</tr>
<tr><td>PostgreSQL 8.2.7</td>
<td>0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ</td>
</tr>
<tr><td>Sqlite3</td>
<td>0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
</dd></dl>
<dl class="attribute">
<dt id="treebeard.mp_tree.MP_Node.node_order_by">
<tt class="descname">node_order_by</tt><a class="headerlink" href="#treebeard.mp_tree.MP_Node.node_order_by" title="Permalink to this definition">¶</a></dt>
<dd><p>Attribute: a list of model fields that will be used for node
ordering. When enabled, all tree operations will assume this ordering.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node_order_by</span> <span class="o">=</span> <span class="p">[</span><span class="s">'field1'</span><span class="p">,</span> <span class="s">'field2'</span><span class="p">,</span> <span class="s">'field3'</span><span class="p">]</span>
</pre></div>
</div>
</dd></dl>
<dl class="attribute">
<dt id="treebeard.mp_tree.MP_Node.path">
<tt class="descname">path</tt><a class="headerlink" href="#treebeard.mp_tree.MP_Node.path" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">CharField</span></tt>, stores the full materialized path for each node. The
default value of it’s max_length, <em>255</em>, is the max efficient and
portable value for a <tt class="docutils literal"><span class="pre">varchar</span></tt>. Increase it to allow deeper trees (max
depth by default: <em>63</em>)</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p><cite>django-treebeard</cite> uses Django’s abstract model inheritance, so:</p>
<ol class="last arabic">
<li><p class="first">To change the max_length value of the path in your model, you
can’t just define it since you’d get a django exception, you have
to modify the already defined attribute:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyNodeModel</span><span class="p">(</span><span class="n">MP_Node</span><span class="p">):</span>
<span class="k">pass</span>
<span class="n">MyNodeModel</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">get_field</span><span class="p">(</span><span class="s">'path'</span><span class="p">)</span><span class="o">.</span><span class="n">max_length</span> <span class="o">=</span> <span class="mi">1024</span>
</pre></div>
</div>
</li>
<li><p class="first">You can’t rely on Django’s <cite>auto_now</cite> properties in date fields
for sorting, you’ll have to manually set the value before creating
a node:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">TestNodeSortedAutoNow</span><span class="p">(</span><span class="n">MP_Node</span><span class="p">):</span>
<span class="n">desc</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">)</span>
<span class="n">created</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">DateTimeField</span><span class="p">(</span><span class="n">auto_now_add</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">node_order_by</span> <span class="o">=</span> <span class="p">[</span><span class="s">'created'</span><span class="p">]</span>
<span class="n">TestNodeSortedAutoNow</span><span class="o">.</span><span class="n">add_root</span><span class="p">(</span><span class="n">desc</span><span class="o">=</span><span class="s">'foo'</span><span class="p">,</span>
<span class="n">created</span><span class="o">=</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
</pre></div>
</div>
</li>
</ol>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">For performance, and if your database allows it, you can safely
define the path column as ASCII (not utf-8/unicode/iso8859-1/etc) to
keep the index smaller (and faster). Also note that some databases
(mysql) have a small index size limit. InnoDB for instance has a
limit of 765 bytes per index, so that would be the limit if your path
is ASCII encoded. If your path column in InnoDB is using unicode,
the index limit will be 255 characters since in MySQL’s indexes,
unicode means 3 bytes.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">treebeard uses <strong>numconv</strong> for path encoding:
<a class="reference external" href="http://code.tabo.pe/numconv/">http://code.tabo.pe/numconv/</a></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="treebeard.mp_tree.MP_Node.depth">
<tt class="descname">depth</tt><a class="headerlink" href="#treebeard.mp_tree.MP_Node.depth" title="Permalink to this definition">¶</a></dt>
<dd><tt class="docutils literal"><span class="pre">PositiveIntegerField</span></tt>, depth of a node in the tree. A root node
has a depth of <em>1</em>.</dd></dl>
<dl class="attribute">
<dt id="treebeard.mp_tree.MP_Node.numchild">
<tt class="descname">numchild</tt><a class="headerlink" href="#treebeard.mp_tree.MP_Node.numchild" title="Permalink to this definition">¶</a></dt>
<dd><tt class="docutils literal"><span class="pre">PositiveIntegerField</span></tt>, the number of children of the node.</dd></dl>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Do not change the values of <a title="treebeard.mp_tree.MP_Node.path" class="reference internal" href="#treebeard.mp_tree.MP_Node.path"><tt class="xref docutils literal"><span class="pre">path</span></tt></a>, <a title="treebeard.mp_tree.MP_Node.depth" class="reference internal" href="#treebeard.mp_tree.MP_Node.depth"><tt class="xref docutils literal"><span class="pre">depth</span></tt></a> or
<a title="treebeard.mp_tree.MP_Node.numchild" class="reference internal" href="#treebeard.mp_tree.MP_Node.numchild"><tt class="xref docutils literal"><span class="pre">numchild</span></tt></a> directly: use one of the included methods instead.
Consider these values <em>read-only</em>.</p>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>Do not change the values of the <a title="treebeard.mp_tree.MP_Node.steplen" class="reference internal" href="#treebeard.mp_tree.MP_Node.steplen"><tt class="xref docutils literal"><span class="pre">steplen</span></tt></a>, <a title="treebeard.mp_tree.MP_Node.alphabet" class="reference internal" href="#treebeard.mp_tree.MP_Node.alphabet"><tt class="xref docutils literal"><span class="pre">alphabet</span></tt></a> or
<a title="treebeard.mp_tree.MP_Node.node_order_by" class="reference internal" href="#treebeard.mp_tree.MP_Node.node_order_by"><tt class="xref docutils literal"><span class="pre">node_order_by</span></tt></a> after saving your first model. Doing so will
corrupt the tree. If you <em>must</em> do it:</p>
<blockquote class="last">
<ol class="arabic simple">
<li>Backup the tree with <tt class="xref docutils literal"><span class="pre">dump_bulk()</span></tt></li>
<li>Empty your model’s table</li>
<li>Change <a title="treebeard.mp_tree.MP_Node.depth" class="reference internal" href="#treebeard.mp_tree.MP_Node.depth"><tt class="xref docutils literal"><span class="pre">depth</span></tt></a>, <a title="treebeard.mp_tree.MP_Node.alphabet" class="reference internal" href="#treebeard.mp_tree.MP_Node.alphabet"><tt class="xref docutils literal"><span class="pre">alphabet</span></tt></a> and/or
<a title="treebeard.mp_tree.MP_Node.node_order_by" class="reference internal" href="#treebeard.mp_tree.MP_Node.node_order_by"><tt class="xref docutils literal"><span class="pre">node_order_by</span></tt></a> in your model</li>
<li>Restore your backup using <tt class="xref docutils literal"><span class="pre">load_bulk()</span></tt> with
<tt class="docutils literal"><span class="pre">keep_ids=True</span></tt> to keep the same primary keys you had.</li>
</ol>
</blockquote>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>Be very careful if you add a <tt class="docutils literal"><span class="pre">Meta</span></tt> class in your
<tt class="xref docutils literal"><span class="pre">mp_tree.MP_Node</span></tt> subclass.
You must add an ordering attribute with a single element on it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="n">ordering</span> <span class="o">=</span> <span class="p">[</span><span class="s">'path'</span><span class="p">]</span>
</pre></div>
</div>
<p class="last">If you don’t, the tree won’t work, since <tt class="xref docutils literal"><span class="pre">mp_tree.MP_Node</span></tt>
completely depends on this attribute.</p>
</div>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">SortedNode</span><span class="p">(</span><span class="n">MP_Node</span><span class="p">):</span>
<span class="n">node_order_by</span> <span class="o">=</span> <span class="p">[</span><span class="s">'numval'</span><span class="p">,</span> <span class="s">'strval'</span><span class="p">]</span>
<span class="n">numval</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span>
<span class="n">strval</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">)</span>
</pre></div>
</div>
<p>Read the API reference of <tt class="xref docutils literal"><span class="pre">treebeard.Node</span></tt> for info on methods
available in this class, or read the following section for methods with
particular arguments or exceptions.</p>
<dl class="classmethod">
<dt id="treebeard.mp_tree.MP_Node.add_root">
<em class="property">classmethod </em><tt class="descname">add_root</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.mp_tree.MP_Node.add_root" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a root node to the tree.</p>
<p>See: <tt class="xref docutils literal"><span class="pre">treebeard.Node.add_root()</span></tt></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name" colspan="2">Raises PathOverflow:</th></tr>
<tr><td> </td><td class="field-body">when no more root objects can be added</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="treebeard.mp_tree.MP_Node.add_child">
<tt class="descname">add_child</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.mp_tree.MP_Node.add_child" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a child to the node.</p>
<p>See: <tt class="xref docutils literal"><span class="pre">treebeard.Node.add_child()</span></tt></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name" colspan="2">Raises PathOverflow:</th></tr>
<tr><td> </td><td class="field-body">when no more child nodes can be added</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="treebeard.mp_tree.MP_Node.add_sibling">
<tt class="descname">add_sibling</tt><big>(</big><em>pos=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.mp_tree.MP_Node.add_sibling" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a new node as a sibling to the current node object.</p>
<p>See: <tt class="xref docutils literal"><span class="pre">treebeard.Node.add_sibling()</span></tt></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name" colspan="2">Raises PathOverflow:</th></tr>
<tr><td> </td><td class="field-body">when the library can’t make room for the
node’s new position</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="treebeard.mp_tree.MP_Node.move">
<tt class="descname">move</tt><big>(</big><em>target</em>, <em>pos=None</em><big>)</big><a class="headerlink" href="#treebeard.mp_tree.MP_Node.move" title="Permalink to this definition">¶</a></dt>
<dd><p>Moves the current node and all it’s descendants to a new position
relative to another node.</p>
<p>See: <tt class="xref docutils literal"><span class="pre">treebeard.Node.move()</span></tt></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name" colspan="2">Raises PathOverflow:</th></tr>
<tr><td> </td><td class="field-body">when the library can’t make room for the
node’s new position</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.mp_tree.MP_Node.get_tree">
<em class="property">classmethod </em><tt class="descname">get_tree</tt><big>(</big><em>parent=None</em><big>)</big><a class="headerlink" href="#treebeard.mp_tree.MP_Node.get_tree" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">A <em>queryset</em> of nodes ordered as DFS, including the parent.
If no parent is given, the entire tree is returned.</td>
</tr>
</tbody>
</table>
<p>See: <tt class="xref docutils literal"><span class="pre">treebeard.Node.get_tree()</span></tt></p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This metod returns a queryset.</p>
</div>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.mp_tree.MP_Node.find_problems">
<em class="property">classmethod </em><tt class="descname">find_problems</tt><big>(</big><big>)</big><a class="headerlink" href="#treebeard.mp_tree.MP_Node.find_problems" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks for problems in the tree structure, problems can occur when:</p>
<blockquote>
<ol class="arabic simple">
<li>your code breaks and you get incomplete transactions (always
use transactions!)</li>
<li>changing the <tt class="docutils literal"><span class="pre">steplen</span></tt> value in a model (you must
<tt class="xref docutils literal"><span class="pre">dump_bulk()</span></tt> first, change <tt class="docutils literal"><span class="pre">steplen</span></tt> and then
<tt class="xref docutils literal"><span class="pre">load_bulk()</span></tt></li>
</ol>
</blockquote>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A tuple of five lists:</p>
<ol class="last arabic simple">
<li>a list of ids of nodes with characters not found in the
<tt class="docutils literal"><span class="pre">alphabet</span></tt></li>
<li>a list of ids of nodes when a wrong <tt class="docutils literal"><span class="pre">path</span></tt> length
according to <tt class="docutils literal"><span class="pre">steplen</span></tt></li>
<li>a list of ids of orphaned nodes</li>
<li>a list of ids of nodes with the wrong depth value for
their path</li>
<li>a list of ids nodes that report a wrong number of children</li>
</ol>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">A node won’t appear in more than one list, even when it exhibits
more than one problem. This method stops checking a node when it
finds a problem and continues to the next node.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Problems 1, 2 and 3 can’t be solved automatically.</p>
</div>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">MyNodeModel</span><span class="o">.</span><span class="n">find_problems</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="classmethod">
<dt id="treebeard.mp_tree.MP_Node.fix_tree">
<em class="property">classmethod </em><tt class="descname">fix_tree</tt><big>(</big><em>destructive=False</em><big>)</big><a class="headerlink" href="#treebeard.mp_tree.MP_Node.fix_tree" title="Permalink to this definition">¶</a></dt>
<dd><p>Solves some problems that can appear when transactions are not used and
a piece of code breaks, leaving the tree in an inconsistent state.</p>
<p>The problems this method solves are:</p>
<blockquote>
<ol class="arabic simple">
<li>Nodes with an incorrect <tt class="docutils literal"><span class="pre">depth</span></tt> or <tt class="docutils literal"><span class="pre">numchild</span></tt> values due to
incorrect code and lack of database transactions.</li>
<li>“Holes” in the tree. This is normal if you move/delete nodes a
lot. Holes in a tree don’t affect performance,</li>
<li>Incorrect ordering of nodes when <tt class="docutils literal"><span class="pre">node_order_by</span></tt> is enabled.
Ordering is enforced on <em>node insertion</em>, so if an attribute in
<tt class="docutils literal"><span class="pre">node_order_by</span></tt> is modified after the node is inserted, the
tree ordering will be inconsistent.</li>
</ol>
</blockquote>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>destructive</em> – <p>A boolean value. If True, a more agressive fix_tree method will be
attemped. If False (the default), it will use a safe (and fast!)
fix approach, but it will only solve the <tt class="docutils literal"><span class="pre">depth</span></tt> and
<tt class="docutils literal"><span class="pre">numchild</span></tt> nodes, it won’t fix the tree holes or broken path
ordering.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>Currently what the <tt class="docutils literal"><span class="pre">destructive</span></tt> method does is:</p>
<ol class="arabic simple">
<li>Backup the tree with <tt class="xref docutils literal"><span class="pre">dump_data()</span></tt></li>
<li>Remove all nodes in the tree.</li>
<li>Restore the tree with <tt class="xref docutils literal"><span class="pre">load_data()</span></tt></li>
</ol>
<p class="last">So, even when the primary keys of your nodes will be preserved,
this method isn’t foreign-key friendly. That needs complex
in-place tree reordering, not available at the moment (hint:
patches are welcome).</p>
</div>
</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">MyNodeModel</span><span class="o">.</span><span class="n">fix_tree</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
</dd></dl>
</div>
</div>
<div class="section" id="module-treebeard.al_tree">
<h1><tt class="xref docutils literal"><span class="pre">treebeard.al_tree</span></tt> — Adjacency List tree<a class="headerlink" href="#module-treebeard.al_tree" title="Permalink to this headline">¶</a></h1>
<div class="section" id="treebeard-al-tree">
<h2>treebeard.al_tree<a class="headerlink" href="#treebeard-al-tree" title="Permalink to this headline">¶</a></h2>
<p>Adjacency List Tree.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">2008-2009 by Gustavo Picon</td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body">Apache License 2.0</td>
</tr>
</tbody>
</table>
<p>This is a simple implementation of the traditional Adjacency List Model for
storing trees in relational databases.</p>
<p>In the adjacency list model, every node will have a
“<a title="treebeard.al_tree.AL_Node.parent" class="reference internal" href="#treebeard.al_tree.AL_Node.parent"><tt class="xref docutils literal"><span class="pre">parent</span></tt></a>” key, that will be NULL for root nodes.</p>
<p>Since <tt class="docutils literal"><span class="pre">django-treebeard</span></tt> must return trees ordered in a predictable way,
the ordering for models without the <a title="treebeard.al_tree.AL_Node.node_order_by" class="reference internal" href="#treebeard.al_tree.AL_Node.node_order_by"><tt class="xref docutils literal"><span class="pre">node_order_by</span></tt></a>
attribute will have an extra attribute that will store the relative
position of a node between it’s siblings: <a title="treebeard.al_tree.AL_Node.sib_order" class="reference internal" href="#treebeard.al_tree.AL_Node.sib_order"><tt class="xref docutils literal"><span class="pre">sib_order</span></tt></a>.</p>
<p>The adjacency list model has the advantage of fast writes at the cost of
slow reads. If you read more than you write, use
<a title="treebeard.mp_tree.MP_Node" class="reference internal" href="#treebeard.mp_tree.MP_Node"><tt class="xref docutils literal"><span class="pre">MP_Node</span></tt></a> instead.</p>
<dl class="class">
<dt id="treebeard.al_tree.AL_Node">
<em class="property">class </em><tt class="descclassname">treebeard.al_tree.</tt><tt class="descname">AL_Node</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.al_tree.AL_Node" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="treebeard.models.Node" class="reference internal" href="#treebeard.models.Node"><tt class="xref docutils literal"><span class="pre">treebeard.models.Node</span></tt></a></p>
<p>Abstract model to create your own Adjacency List Trees.</p>
<dl class="attribute">
<dt id="treebeard.al_tree.AL_Node.node_order_by">
<tt class="descname">node_order_by</tt><a class="headerlink" href="#treebeard.al_tree.AL_Node.node_order_by" title="Permalink to this definition">¶</a></dt>
<dd><p>Attribute: a list of model fields that will be used for node
ordering. When enabled, all tree operations will assume this ordering.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node_order_by</span> <span class="o">=</span> <span class="p">[</span><span class="s">'field1'</span><span class="p">,</span> <span class="s">'field2'</span><span class="p">,</span> <span class="s">'field3'</span><span class="p">]</span>
</pre></div>
</div>
</dd></dl>
<dl class="attribute">
<dt id="treebeard.al_tree.AL_Node.parent">
<tt class="descname">parent</tt><a class="headerlink" href="#treebeard.al_tree.AL_Node.parent" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">ForeignKey</span></tt> to itself. This attribute <strong>MUST</strong> be defined in the
subclass (sadly, this isn’t inherited correctly from the ABC in
<cite>Django 1.0</cite>). Just copy&paste these lines to your model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">parent</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="s">'self'</span><span class="p">,</span>
<span class="n">related_name</span><span class="o">=</span><span class="s">'children_set'</span><span class="p">,</span>
<span class="n">null</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">db_index</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="attribute">
<dt id="treebeard.al_tree.AL_Node.sib_order">
<tt class="descname">sib_order</tt><a class="headerlink" href="#treebeard.al_tree.AL_Node.sib_order" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">PositiveIntegerField</span></tt> used to store the relative position of a node
between it’s siblings. This attribute is mandatory <em>ONLY</em> if you don’t
set a <a title="treebeard.al_tree.AL_Node.node_order_by" class="reference internal" href="#treebeard.al_tree.AL_Node.node_order_by"><tt class="xref docutils literal"><span class="pre">node_order_by</span></tt></a> field. You can define it copy&pasting this
line in your model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">sib_order</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">PositiveIntegerField</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<p>Examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">AL_TestNode</span><span class="p">(</span><span class="n">AL_Node</span><span class="p">):</span>
<span class="n">parent</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="s">'self'</span><span class="p">,</span>
<span class="n">related_name</span><span class="o">=</span><span class="s">'children_set'</span><span class="p">,</span>
<span class="n">null</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">db_index</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">sib_order</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">PositiveIntegerField</span><span class="p">()</span>
<span class="n">desc</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">AL_TestNodeSorted</span><span class="p">(</span><span class="n">AL_Node</span><span class="p">):</span>
<span class="n">parent</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="s">'self'</span><span class="p">,</span>
<span class="n">related_name</span><span class="o">=</span><span class="s">'children_set'</span><span class="p">,</span>
<span class="n">null</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">db_index</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">node_order_by</span> <span class="o">=</span> <span class="p">[</span><span class="s">'val1'</span><span class="p">,</span> <span class="s">'val2'</span><span class="p">,</span> <span class="s">'desc'</span><span class="p">]</span>
<span class="n">val1</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span>
<span class="n">val2</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span>
<span class="n">desc</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">)</span>
</pre></div>
</div>
<p>Read the API reference of <tt class="xref docutils literal"><span class="pre">treebeard.Node</span></tt> for info on methods
available in this class, or read the following section for methods with
particular arguments or exceptions.</p>
<dl class="method">
<dt id="treebeard.al_tree.AL_Node.get_depth">
<tt class="descname">get_depth</tt><big>(</big><em>update=False</em><big>)</big><a class="headerlink" href="#treebeard.al_tree.AL_Node.get_depth" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">the depth (level) of the node
Caches the result in the object itself to help in loops.</td>
</tr>
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>update</em> – Updates the cached value.</td>
</tr>
</tbody>
</table>
<p>See: <tt class="xref docutils literal"><span class="pre">treebeard.Node.get_depth()</span></tt></p>
</dd></dl>
</dd></dl>
</div>
</div>
<div class="section" id="module-treebeard.ns_tree">
<h1><tt class="xref docutils literal"><span class="pre">treebeard.ns_tree</span></tt> — Nested Sets tree<a class="headerlink" href="#module-treebeard.ns_tree" title="Permalink to this headline">¶</a></h1>
<div class="section" id="treebeard-ns-tree">
<h2>treebeard.ns_tree<a class="headerlink" href="#treebeard-ns-tree" title="Permalink to this headline">¶</a></h2>
<p>Nested Sets Tree.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">2008-2009 by Gustavo Picon</td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body">Apache License 2.0</td>
</tr>
</tbody>
</table>
<p>An implementation of Nested Sets trees for Django 1.0+, as described by
<a class="reference external" href="http://www.celko.com/">Joe Celko</a> in <a class="reference external" href="http://www.elsevier.com/wps/find/bookdescription.cws_home/702605/description">Trees and Hierarchies in SQL for Smarties</a>.</p>
<p>Nested sets have very efficient reads at the cost of high maintenance on
write/delete operations.</p>
<dl class="class">
<dt id="treebeard.ns_tree.NS_Node">
<em class="property">class </em><tt class="descclassname">treebeard.ns_tree.</tt><tt class="descname">NS_Node</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#treebeard.ns_tree.NS_Node" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="treebeard.models.Node" class="reference internal" href="#treebeard.models.Node"><tt class="xref docutils literal"><span class="pre">treebeard.models.Node</span></tt></a></p>
<p>Abstract model to create your own Nested Sets Trees.</p>
<dl class="attribute">
<dt id="treebeard.ns_tree.NS_Node.node_order_by">
<tt class="descname">node_order_by</tt><a class="headerlink" href="#treebeard.ns_tree.NS_Node.node_order_by" title="Permalink to this definition">¶</a></dt>
<dd><p>Attribute: a list of model fields that will be used for node
ordering. When enabled, all tree operations will assume this ordering.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">node_order_by</span> <span class="o">=</span> <span class="p">[</span><span class="s">'field1'</span><span class="p">,</span> <span class="s">'field2'</span><span class="p">,</span> <span class="s">'field3'</span><span class="p">]</span>
</pre></div>
</div>
</dd></dl>
<dl class="attribute">
<dt id="treebeard.ns_tree.NS_Node.depth">
<tt class="descname">depth</tt><a class="headerlink" href="#treebeard.ns_tree.NS_Node.depth" title="Permalink to this definition">¶</a></dt>
<dd><tt class="docutils literal"><span class="pre">PositiveIntegerField</span></tt>, depth of a node in the tree. A root node
has a depth of <em>1</em>.</dd></dl>
<dl class="attribute">
<dt id="treebeard.ns_tree.NS_Node.lft">
<tt class="descname">lft</tt><a class="headerlink" href="#treebeard.ns_tree.NS_Node.lft" title="Permalink to this definition">¶</a></dt>
<dd><tt class="docutils literal"><span class="pre">PositiveIntegerField</span></tt></dd></dl>
<dl class="attribute">
<dt id="treebeard.ns_tree.NS_Node.rgt">
<tt class="descname">rgt</tt><a class="headerlink" href="#treebeard.ns_tree.NS_Node.rgt" title="Permalink to this definition">¶</a></dt>
<dd><tt class="docutils literal"><span class="pre">PositiveIntegerField</span></tt></dd></dl>
<dl class="attribute">
<dt id="treebeard.ns_tree.NS_Node.tree_id">
<tt class="descname">tree_id</tt><a class="headerlink" href="#treebeard.ns_tree.NS_Node.tree_id" title="Permalink to this definition">¶</a></dt>
<dd><tt class="docutils literal"><span class="pre">PositiveIntegerField</span></tt></dd></dl>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>Be very careful if you add a <tt class="docutils literal"><span class="pre">Meta</span></tt> class in your
<tt class="xref docutils literal"><span class="pre">ns_tree.NS_Node</span></tt> subclass.
You must add an ordering attribute with two elements on it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="n">ordering</span> <span class="o">=</span> <span class="p">[</span><span class="s">'tree_id'</span><span class="p">,</span> <span class="s">'lft'</span><span class="p">]</span>
</pre></div>
</div>
<p class="last">If you don’t, the tree won’t work, since <tt class="xref docutils literal"><span class="pre">ns_tree.NS_Node</span></tt>
completely depends on this attribute.</p>
</div>
<dl class="classmethod">
<dt id="treebeard.ns_tree.NS_Node.get_tree">
<em class="property">classmethod </em><tt class="descname">get_tree</tt><big>(</big><em>parent=None</em><big>)</big><a class="headerlink" href="#treebeard.ns_tree.NS_Node.get_tree" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Returns:</th><td class="field-body">A <em>queryset</em> of nodes ordered as DFS, including the parent.
If no parent is given, all trees are returned.</td>
</tr>
</tbody>
</table>
<p>See: <tt class="xref docutils literal"><span class="pre">treebeard.Node.get_tree()</span></tt></p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This metod returns a queryset.</p>
</div>
</dd></dl>
</dd></dl>
</div>
</div>
<div class="section" id="module-treebeard.admin">
<h1><tt class="xref docutils literal"><span class="pre">treebeard.admin</span></tt> — Admin<a class="headerlink" href="#module-treebeard.admin" title="Permalink to this headline">¶</a></h1>
<div class="section" id="treebeard-admin">
<h2>treebeard.admin<a class="headerlink" href="#treebeard-admin" title="Permalink to this headline">¶</a></h2>
<p>Django admin support.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">2008-2009 by Gustavo Picon</td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body">Apache License 2.0</td>
</tr>
</tbody>
</table>
<p>Original contribution by aleh.fl</p>
<dl class="class">
<dt id="treebeard.admin.TreeAdmin">
<em class="property">class </em><tt class="descclassname">treebeard.admin.</tt><tt class="descname">TreeAdmin</tt><big>(</big><em>model</em>, <em>admin_site</em><big>)</big><a class="headerlink" href="#treebeard.admin.TreeAdmin" title="Permalink to this definition">¶</a></dt>
<dd><p>Django Admin class for treebeard</p>
<p>To be used by Django’s admin.site.register</p>
</dd></dl>
</div>
</div>
<div class="section" id="module-treebeard.forms">
<h1><tt class="xref docutils literal"><span class="pre">treebeard.forms</span></tt> — Forms<a class="headerlink" href="#module-treebeard.forms" title="Permalink to this headline">¶</a></h1>
<div class="section" id="treebeard-forms">
<h2>treebeard.forms<a class="headerlink" href="#treebeard-forms" title="Permalink to this headline">¶</a></h2>
<p>Forms for treebeard.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">2008-2009 by Gustavo Picon</td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body">Apache License 2.0</td>
</tr>
</tbody>
</table>
<p>Original contribution by aleh.fl</p>
<dl class="class">
<dt id="treebeard.forms.MoveNodeForm">
<em class="property">class </em><tt class="descclassname">treebeard.forms.</tt><tt class="descname">MoveNodeForm</tt><big>(</big><em>data=None</em>, <em>files=None</em>, <em>auto_id='id_%s'</em>, <em>prefix=None</em>, <em>initial=None</em>, <em>error_class=<class 'django.forms.util.ErrorList'></em>, <em>label_suffix=':'</em>, <em>empty_permitted=False</em>, <em>instance=None</em><big>)</big><a class="headerlink" href="#treebeard.forms.MoveNodeForm" title="Permalink to this definition">¶</a></dt>
<dd><p>Form to handle moving a node in a tree.</p>
<p>Handles sorted/unsorted trees.</p>
<p>Read the <a class="reference external" href="http://docs.djangoproject.com/en/dev/topics/forms/#form-objects">Django Form objects documentation</a> for reference.</p>
</dd></dl>
</div>
</div>
<div class="section" id="module-treebeard.exceptions">
<h1><tt class="xref docutils literal"><span class="pre">treebeard.exceptions</span></tt> — Exceptions<a class="headerlink" href="#module-treebeard.exceptions" title="Permalink to this headline">¶</a></h1>
<div class="section" id="treebeard-exceptions">
<h2>treebeard.exceptions<a class="headerlink" href="#treebeard-exceptions" title="Permalink to this headline">¶</a></h2>
<p>Exceptions</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">2008-2009 by Gustavo Picon</td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body">Apache License 2.0</td>
</tr>
</tbody>
</table>
<dl class="exception">
<dt id="treebeard.exceptions.InvalidPosition">
<em class="property">exception </em><tt class="descclassname">treebeard.exceptions.</tt><tt class="descname">InvalidPosition</tt><a class="headerlink" href="#treebeard.exceptions.InvalidPosition" title="Permalink to this definition">¶</a></dt>
<dd>Raised when passing an invalid pos value</dd></dl>
<dl class="exception">
<dt id="treebeard.exceptions.InvalidMoveToDescendant">
<em class="property">exception </em><tt class="descclassname">treebeard.exceptions.</tt><tt class="descname">InvalidMoveToDescendant</tt><a class="headerlink" href="#treebeard.exceptions.InvalidMoveToDescendant" title="Permalink to this definition">¶</a></dt>
<dd>Raised when attemping to move a node to one of it’s descendants.</dd></dl>
<dl class="exception">
<dt id="treebeard.exceptions.PathOverflow">
<em class="property">exception </em><tt class="descclassname">treebeard.exceptions.</tt><tt class="descname">PathOverflow</tt><a class="headerlink" href="#treebeard.exceptions.PathOverflow" title="Permalink to this definition">¶</a></dt>
<dd>Raised when trying to add or move a node to a position where no more nodes
can be added (see <tt class="xref docutils literal"><span class="pre">path</span></tt> and
<tt class="xref docutils literal"><span class="pre">alphabet</span></tt> for more info)</dd></dl>
<dl class="exception">
<dt id="treebeard.exceptions.MissingNodeOrderBy">
<em class="property">exception </em><tt class="descclassname">treebeard.exceptions.</tt><tt class="descname">MissingNodeOrderBy</tt><a class="headerlink" href="#treebeard.exceptions.MissingNodeOrderBy" title="Permalink to this definition">¶</a></dt>
<dd>Raised when an operation needs a missing
<tt class="xref docutils literal"><span class="pre">node_order_by</span></tt> attribute</dd></dl>
</div>
</div>
<div class="section" id="module-tbbench">
<h1><tt class="xref docutils literal"><span class="pre">tbbench</span></tt> — Benchmarks<a class="headerlink" href="#module-tbbench" title="Permalink to this headline">¶</a></h1>
<div class="section" id="tbbench-lies-damn-lies-and-benchmarks-for-treebeard">
<h2>tbbench - Lies, damn lies, and benchmarks for treebeard<a class="headerlink" href="#tbbench-lies-damn-lies-and-benchmarks-for-treebeard" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">synopsys:</th><td class="field-body">Benchmarks for <tt class="docutils literal"><span class="pre">treebeard</span></tt></td>
</tr>
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">2008-2009 by Gustavo Picon</td>
</tr>
<tr class="field"><th class="field-name">license:</th><td class="field-body">Apache License 2.0</td>
</tr>
</tbody>
</table>
<p>tbbench is a django app that isn’t installed by default. I wrote it to find
spots that could be optimized, and it may help you to tweak your database
settings.</p>
<p>To run the benchmarks:</p>
<blockquote>
<ol class="arabic simple">
<li>Add <tt class="docutils literal"><span class="pre">tbbench</span></tt> to your Python path</li>
<li>Add <tt class="docutils literal"><span class="pre">'tbbench'</span></tt> to the <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt> section in your django
settings file.</li>
<li>Run <strong>python manage.py syncdb</strong></li>
<li>In the <tt class="docutils literal"><span class="pre">tbbench</span></tt> dir, run <strong>python run.py</strong></li>
</ol>
</blockquote>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If the <a class="reference external" href="http://code.google.com/p/django-mptt/">django-mptt</a> package is also installed, both libraries will
be tested with the exact same data and operations.</p>
</div>
<p>Currently, the available tests are:</p>
<blockquote>
<ol class="arabic simple">
<li>Inserts: adds 1000 nodes to a tree, in different places: root
nodes, normal nodes, leaf nodes</li>
<li>Descendants: retrieves the full branch under every node several times.</li>
<li>Move: moves nodes several times. This operation can be expensive
because involves reodrering and data maintenance.</li>
<li>Delete: Removes groups of nodes.</li>
</ol>
</blockquote>
<p>For every available library (treebeard and mptt), two models are tested: a
vanilla model, and a model with a “tree order by” attribute enabled
(<tt class="xref docutils literal"><span class="pre">node_order_by</span></tt> in treebeard,
<tt class="docutils literal"><span class="pre">order_insertion_by</span></tt> in mptt).</p>
<p>Also, every test will be tested with and without database transactions
(<tt class="docutils literal"><span class="pre">tx</span></tt>).</p>
<p>The output of the script is a reST table, with the time for every test in
milliseconds (so small numbers are better).</p>
<p>By default, these tests use the default tables created by <tt class="docutils literal"><span class="pre">syncdb</span></tt>. Even
when the results of <tt class="docutils literal"><span class="pre">treebeard</span></tt> are good, they can be improved <em>a lot</em>
with better indexing. The Materialized Path Tree approach used by
<tt class="docutils literal"><span class="pre">treebeard</span></tt> is <em>very</em> sensitive to database indexing, so you’ll
probably want to <tt class="docutils literal"><span class="pre">EXPLAIN</span></tt> your most common queries involving the
<tt class="xref docutils literal"><span class="pre">path</span></tt> field and add proper indexes.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Tests results in Ubuntu 8.04.1 on a Thinkpad T61 with 4GB of ram.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">These results shouldn’t be taken as <em>“X is faster than Y”</em>,
but as <em>“both X and Y are very fast”</em>.</p>
</div>
<p>Databases tested:</p>
<blockquote>
<ul class="simple">
<li>MySQL InnoDB 5.0.51a, default settings</li>
<li>MySQL MyISAM 5.0.51a, default settings</li>
<li>PostgreSQL 8.2.7, default settings, mounted on RAM</li>
<li>PostgreSQL 8.3.3, default settings, mounted on RAM</li>
<li>SQLite3, mounted on RAM</li>
</ul>
</blockquote>
<table border="1" class="last docutils">
<colgroup>
<col width="11%" />
<col width="12%" />
<col width="8%" />
<col width="8%" />
<col width="8%" />
<col width="8%" />
<col width="8%" />
<col width="8%" />
<col width="8%" />
<col width="8%" />
<col width="8%" />
<col width="8%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head" rowspan="2">Test</th>
<th class="head" rowspan="2">Model</th>
<th class="head" colspan="2">innodb</th>
<th class="head" colspan="2">myisam</th>
<th class="head" colspan="2">pg82</th>
<th class="head" colspan="2">pg83</th>
<th class="head" colspan="2">sqlite</th>
</tr>
<tr><th class="head">no tx</th>
<th class="head">tx</th>
<th class="head">no tx</th>
<th class="head">tx</th>
<th class="head">no tx</th>
<th class="head">tx</th>
<th class="head">no tx</th>
<th class="head">tx</th>
<th class="head">no tx</th>
<th class="head">tx</th>
</tr>
</thead>
<tbody valign="top">
<tr><td rowspan="8">Inserts</td>
<td>TB MP</td>
<td>3220</td>
<td>2660</td>
<td>3181</td>
<td>2766</td>
<td>2859</td>
<td>2542</td>
<td>2540</td>
<td>2309</td>
<td>2205</td>
<td>1934</td>
</tr>
<tr><td>TB AL</td>
<td>1963</td>
<td>1905</td>
<td>1998</td>
<td>1936</td>
<td>1937</td>
<td>1775</td>
<td>1736</td>
<td>1631</td>
<td>1583</td>
<td>1457</td>
</tr>
<tr><td>TB NS</td>
<td>3386</td>
<td>3438</td>
<td>3359</td>
<td>3420</td>
<td>4061</td>
<td>7242</td>
<td>3536</td>
<td>4401</td>
<td>2794</td>
<td>2554</td>
</tr>
<tr><td>MPTT</td>
<td>7559</td>
<td>9280</td>
<td>7525</td>
<td>9028</td>
<td>5202</td>
<td>14969</td>
<td>4764</td>
<td>6022</td>
<td>3781</td>
<td>3484</td>
</tr>
<tr><td>TB MP Sorted</td>
<td>4732</td>
<td>5627</td>
<td>5038</td>
<td>5215</td>
<td>4022</td>
<td>4808</td>
<td>3415</td>
<td>3942</td>
<td>3250</td>
<td>3045</td>
</tr>
<tr><td>TB AL Sorted</td>
<td>1096</td>
<td>1052</td>
<td>1092</td>
<td>1033</td>
<td>1239</td>
<td>999</td>
<td>1049</td>
<td>896</td>
<td>860</td>
<td>705</td>
</tr>
<tr><td>TB NS Sorted</td>
<td>6637</td>
<td>6373</td>
<td>6283</td>
<td>6313</td>
<td>7548</td>
<td>10053</td>
<td>6717</td>
<td>10941</td>
<td>5907</td>
<td>5461</td>
</tr>
<tr><td>MPTT Sorted</td>
<td>8564</td>
<td>10729</td>
<td>7947</td>
<td>10221</td>
<td>6077</td>
<td>7567</td>
<td>5490</td>
<td>6894</td>
<td>4842</td>
<td>4284</td>
</tr>
<tr><td rowspan="8">Descendants</td>
<td>TB MP</td>
<td>6298</td>
<td>N/A</td>
<td>6460</td>
<td>N/A</td>
<td>7643</td>
<td>N/A</td>
<td>7132</td>
<td>N/A</td>
<td>10415</td>
<td>N/A</td>
</tr>
<tr><td>TB AL</td>
<td>56850</td>
<td>N/A</td>
<td>116550</td>
<td>N/A</td>
<td>54249</td>
<td>N/A</td>
<td>50682</td>
<td>N/A</td>
<td>50521</td>
<td>N/A</td>
</tr>
<tr><td>TB NS</td>
<td>5595</td>
<td>N/A</td>
<td>5824</td>
<td>N/A</td>
<td>10080</td>
<td>N/A</td>
<td>5840</td>
<td>N/A</td>
<td>5965</td>
<td>N/A</td>
</tr>
<tr><td>MPTT</td>
<td>5268</td>
<td>N/A</td>
<td>5306</td>
<td>N/A</td>
<td>9394</td>
<td>N/A</td>
<td>8745</td>
<td>N/A</td>
<td>5197</td>
<td>N/A</td>
</tr>
<tr><td>TB MP Sorted</td>
<td>6698</td>
<td>N/A</td>
<td>6408</td>
<td>N/A</td>
<td>8248</td>
<td>N/A</td>
<td>7265</td>
<td>N/A</td>
<td>10513</td>
<td>N/A</td>
</tr>
<tr><td>TB AL Sorted</td>
<td>59817</td>
<td>N/A</td>
<td>59718</td>
<td>N/A</td>
<td>56767</td>
<td>N/A</td>
<td>52574</td>
<td>N/A</td>
<td>53458</td>
<td>N/A</td>
</tr>
<tr><td>TB NS Sorted</td>
<td>5631</td>
<td>N/A</td>
<td>5858</td>
<td>N/A</td>
<td>9980</td>
<td>N/A</td>
<td>9210</td>
<td>N/A</td>
<td>6026</td>
<td>N/A</td>
</tr>
<tr><td>MPTT Sorted</td>
<td>5186</td>
<td>N/A</td>
<td>5453</td>
<td>N/A</td>
<td>9723</td>
<td>N/A</td>
<td>8912</td>
<td>N/A</td>
<td>5333</td>
<td>N/A</td>
</tr>
<tr><td rowspan="8">Move</td>
<td>TB MP</td>
<td>837</td>
<td>1156</td>
<td>992</td>
<td>1211</td>
<td>745</td>
<td>1040</td>
<td>603</td>
<td>740</td>
<td>497</td>
<td>468</td>
</tr>
<tr><td>TB AL</td>
<td>8708</td>
<td>8684</td>
<td>9798</td>
<td>8890</td>
<td>7243</td>
<td>7213</td>
<td>6721</td>
<td>6757</td>
<td>7051</td>
<td>6863</td>
</tr>
<tr><td>TB NS</td>
<td>683</td>
<td>658</td>
<td>660</td>
<td>679</td>
<td>1266</td>
<td>2000</td>
<td>650</td>
<td>907</td>
<td>672</td>
<td>637</td>
</tr>
<tr><td>MPTT</td>
<td>6449</td>
<td>7793</td>
<td>6356</td>
<td>7003</td>
<td>4993</td>
<td>20743</td>
<td>4445</td>
<td>8977</td>
<td>921</td>
<td>896</td>
</tr>
<tr><td>TB MP Sorted</td>
<td>6730</td>
<td>7036</td>
<td>6743</td>
<td>7023</td>
<td>6410</td>
<td>19294</td>
<td>3622</td>
<td>12380</td>
<td>2622</td>
<td>2487</td>
</tr>
<tr><td>TB AL Sorted</td>
<td>3866</td>
<td>3731</td>
<td>3873</td>
<td>3717</td>
<td>3587</td>
<td>3599</td>
<td>3394</td>
<td>3371</td>
<td>3491</td>
<td>3416</td>
</tr>
<tr><td>TB NS Sorted</td>
<td>2017</td>
<td>2017</td>
<td>1958</td>
<td>2078</td>
<td>4397</td>
<td>7981</td>
<td>3892</td>
<td>8110</td>
<td>1543</td>
<td>1496</td>
</tr>
<tr><td>MPTT Sorted</td>
<td>6563</td>
<td>10540</td>
<td>6427</td>
<td>9358</td>
<td>5132</td>
<td>20426</td>
<td>4601</td>
<td>9428</td>
<td>957</td>
<td>955</td>
</tr>
<tr><td rowspan="8">Delete</td>
<td>TB MP</td>
<td>714</td>
<td>651</td>
<td>733</td>
<td>686</td>
<td>699</td>
<td>689</td>
<td>595</td>
<td>561</td>
<td>636</td>
<td>557</td>
</tr>
<tr><td>TB AL</td>
<td>975</td>
<td>1093</td>
<td>2199</td>
<td>991</td>
<td>758</td>
<td>847</td>
<td>714</td>
<td>804</td>
<td>843</td>
<td>921</td>
</tr>
<tr><td>TB NS</td>
<td>745</td>
<td>745</td>
<td>742</td>
<td>763</td>
<td>555</td>
<td>698</td>
<td>430</td>
<td>506</td>
<td>530</td>
<td>513</td>
</tr>
<tr><td>MPTT</td>
<td>2928</td>
<td>4473</td>
<td>2914</td>
<td>4814</td>
<td>69385</td>
<td>167777</td>
<td>18186</td>
<td>26270</td>
<td>1617</td>
<td>1635</td>
</tr>
<tr><td>TB MP Sorted</td>
<td>811</td>
<td>751</td>
<td>808</td>
<td>737</td>
<td>798</td>
<td>1180</td>
<td>648</td>
<td>1101</td>
<td>612</td>
<td>565</td>
</tr>
<tr><td>TB AL Sorted</td>
<td>1030</td>
<td>1030</td>
<td>1055</td>
<td>987</td>
<td>797</td>
<td>1023</td>
<td>760</td>
<td>969</td>
<td>884</td>
<td>859</td>
</tr>
<tr><td>TB NS Sorted</td>
<td>756</td>
<td>750</td>
<td>728</td>
<td>758</td>
<td>807</td>
<td>847</td>
<td>576</td>
<td>748</td>
<td>501</td>
<td>490</td>
</tr>
<tr><td>MPTT Sorted</td>
<td>3729</td>
<td>5108</td>
<td>3833</td>
<td>4776</td>
<td>86545</td>
<td>148596</td>
<td>34059</td>
<td>127125</td>
<td>2024</td>
<td>1787</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="section" id="changes-in-django-treebeard">
<h1>Changes in django-treebeard<a class="headerlink" href="#changes-in-django-treebeard" title="Permalink to this headline">¶</a></h1>
<div class="section" id="release-1-5-dec-15-2009">
<h2>Release 1.5 (Dec 15, 2009)<a class="headerlink" href="#release-1-5-dec-15-2009" title="Permalink to this headline">¶</a></h2>
<div class="section" id="new-features-added">
<h3>New features added<a class="headerlink" href="#new-features-added" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li>Forms<ul>
<li>Added MoveNodeForm</li>
</ul>
</li>
<li>Django Admin<ul>
<li>Added TreeAdmin</li>
</ul>
</li>
<li>MP_Node<ul>
<li>Added 2 new checks in MP_Node.find_problems():<ol class="arabic" start="4">
<li>a list of ids of nodes with the wrong depth value for
their path</li>
<li>a list of ids nodes that report a wrong number of children</li>
</ol>
</li>
<li>Added a new (safer and faster but less comprehensive) MP_Node.fix_tree()
approach.</li>
</ul>
</li>
<li>Documentation<ul>
<li>Added warnings in the documentation when subclassing MP_Node or NS_Node
and adding a new Meta.</li>
<li>HTML documentation is now included in the package.</li>
<li>CHANGES file and section in the docs.</li>
</ul>
</li>
<li>Other changes:<ul>
<li>script to build documentation</li>
<li>updated numconv.py</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="bugs-fixed">
<h3>Bugs fixed<a class="headerlink" href="#bugs-fixed" title="Permalink to this headline">¶</a></h3>
<blockquote>
<ul class="simple">
<li>Added table quoting to all the sql queries that bypass the ORM.
Solves bug in postgres when the table isn’t created by syncdb.</li>
<li>removing unused method NS_Node._find_next_node</li>
<li>Fixed MP_Node.get_tree to include the given parent when given a leaf node</li>
</ul>
</blockquote>
</div>
</div>
<div class="section" id="release-1-1-nov-20-2008">
<h2>Release 1.1 (Nov 20, 2008)<a class="headerlink" href="#release-1-1-nov-20-2008" title="Permalink to this headline">¶</a></h2>
<div class="section" id="id1">
<h3>Bugs fixed<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li>Added exceptions.py</li>
</ul>
</div>
</div>
<div class="section" id="release-1-0-nov-19-2008">
<h2>Release 1.0 (Nov 19, 2008)<a class="headerlink" href="#release-1-0-nov-19-2008" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li>First public release.</li>
</ul>
</div>
</div>
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
<ul class="simple">
<li><a class="reference external" href="genindex.html"><em>Index</em></a></li>
<li><a class="reference external" href="modindex.html"><em>Module Index</em></a></li>
<li><a class="reference external" href="search.html"><em>Search Page</em></a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="">Table Of Contents</a></h3>
<ul>
<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">treebeard</span></tt> — Efficient tree model implementations for Django</a><ul>
<li><a class="reference external" href="#treebeard">treebeard</a></li>
<li><a class="reference external" href="#treebeard-models">treebeard.models</a></li>
</ul>
</li>
<li><a class="reference external" href="#module-treebeard.mp_tree"><tt class="docutils literal"><span class="pre">treebeard.mp_tree</span></tt> — Materialized Path tree</a><ul>
<li><a class="reference external" href="#treebeard-mp-tree">treebeard.mp_tree</a></li>
</ul>
</li>
<li><a class="reference external" href="#module-treebeard.al_tree"><tt class="docutils literal"><span class="pre">treebeard.al_tree</span></tt> — Adjacency List tree</a><ul>
<li><a class="reference external" href="#treebeard-al-tree">treebeard.al_tree</a></li>
</ul>
</li>
<li><a class="reference external" href="#module-treebeard.ns_tree"><tt class="docutils literal"><span class="pre">treebeard.ns_tree</span></tt> — Nested Sets tree</a><ul>
<li><a class="reference external" href="#treebeard-ns-tree">treebeard.ns_tree</a></li>
</ul>
</li>
<li><a class="reference external" href="#module-treebeard.admin"><tt class="docutils literal"><span class="pre">treebeard.admin</span></tt> — Admin</a><ul>
<li><a class="reference external" href="#treebeard-admin">treebeard.admin</a></li>
</ul>
</li>
<li><a class="reference external" href="#module-treebeard.forms"><tt class="docutils literal"><span class="pre">treebeard.forms</span></tt> — Forms</a><ul>
<li><a class="reference external" href="#treebeard-forms">treebeard.forms</a></li>
</ul>
</li>
<li><a class="reference external" href="#module-treebeard.exceptions"><tt class="docutils literal"><span class="pre">treebeard.exceptions</span></tt> — Exceptions</a><ul>
<li><a class="reference external" href="#treebeard-exceptions">treebeard.exceptions</a></li>
</ul>
</li>
<li><a class="reference external" href="#module-tbbench"><tt class="docutils literal"><span class="pre">tbbench</span></tt> — Benchmarks</a><ul>
<li><a class="reference external" href="#tbbench-lies-damn-lies-and-benchmarks-for-treebeard">tbbench - Lies, damn lies, and benchmarks for treebeard</a></li>
</ul>
</li>
<li><a class="reference external" href="#changes-in-django-treebeard">Changes in django-treebeard</a><ul>
<li><a class="reference external" href="#release-1-5-dec-15-2009">Release 1.5 (Dec 15, 2009)</a><ul>
<li><a class="reference external" href="#new-features-added">New features added</a></li>
<li><a class="reference external" href="#bugs-fixed">Bugs fixed</a></li>
</ul>
</li>
<li><a class="reference external" href="#release-1-1-nov-20-2008">Release 1.1 (Nov 20, 2008)</a><ul>
<li><a class="reference external" href="#id1">Bugs fixed</a></li>
</ul>
</li>
<li><a class="reference external" href="#release-1-0-nov-19-2008">Release 1.0 (Nov 19, 2008)</a></li>
</ul>
</li>
<li><a class="reference external" href="#indices-and-tables">Indices and tables</a></li>
</ul>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/index.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="modindex.html" title="Global Module Index"
>modules</a> |</li>
<li><a href="">django-treebeard v1.5 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2008-2009, Gustavo Picon.
Last updated on Dec 15, 2009.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
</div>
</body>
</html>
|