/usr/share/doc/python-django-treebeard-doc/html/intro.html is in python-django-treebeard-doc 2.0~beta1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!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>Introduction — django-treebeard 2.0b1 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: '2.0b1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="django-treebeard 2.0b1 documentation" href="index.html" />
<link rel="next" title="API" href="api.html" />
<link rel="prev" title="django-treebeard" href="index.html" />
</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="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="api.html" title="API"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="django-treebeard"
accesskey="P">previous</a> |</li>
<li><a href="index.html">django-treebeard 2.0b1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="introduction">
<h1>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h1>
<p>Everything you need to get working quickly.</p>
<div class="section" id="prerequisites">
<h2>Prerequisites<a class="headerlink" href="#prerequisites" title="Permalink to this headline">¶</a></h2>
<p><tt class="docutils literal"><span class="pre">django-treebeard</span></tt> needs at least <strong>Python 2.5</strong> to run, and
<strong>Django 1.4 or better</strong>.</p>
</div>
<div class="section" id="installation">
<h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<p>You have several ways to install <tt class="docutils literal"><span class="pre">django-treebeard</span></tt>. If you’re not sure,
<a class="reference external" href="http://guide.python-distribute.org/pip.html">just use pip</a></p>
<div class="section" id="pip-or-easy-install">
<h3>pip (or easy_install)<a class="headerlink" href="#pip-or-easy-install" title="Permalink to this headline">¶</a></h3>
<p>You can install the release versions from
<a class="reference external" href="http://pypi.python.org/pypi/django-treebeard">django-treebeard’s PyPI page</a> using <tt class="docutils literal"><span class="pre">pip</span></tt>:</p>
<div class="highlight-python"><pre>pip install django-treebeard</pre>
</div>
<p>or if for some reason you can’t use <tt class="docutils literal"><span class="pre">pip</span></tt>, you can try <tt class="docutils literal"><span class="pre">easy_install</span></tt>,
(at your own risk):</p>
<div class="highlight-python"><pre>easy_install --always-unzip django-treebeard</pre>
</div>
</div>
<div class="section" id="setup-py">
<h3>setup.py<a class="headerlink" href="#setup-py" title="Permalink to this headline">¶</a></h3>
<p>Download a release from the <a class="reference external" href="https://tabo.pe/projects/django-treebeard/download/">treebeard download page</a> and unpack it, then
run:</p>
<div class="highlight-python"><pre>python setup.py install</pre>
</div>
</div>
<div class="section" id="deb-packages">
<h3>.deb packages<a class="headerlink" href="#deb-packages" title="Permalink to this headline">¶</a></h3>
<p>Both Debian and Ubuntu include <tt class="docutils literal"><span class="pre">django-treebeard</span></tt> as a package, so you can
just use:</p>
<div class="highlight-python"><pre>apt-get install python-django-treebeard</pre>
</div>
<p>or:</p>
<div class="highlight-python"><pre>aptitude install python-django-treebeard</pre>
</div>
<p>Remember that the packages included in linux distributions are usually not the
most recent versions.</p>
</div>
</div>
<div class="section" id="configuration">
<h2>Configuration<a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h2>
<p>Add <tt class="docutils literal"><span class="pre">'treebeard'</span></tt> to the <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#installed-apps">INSTALLED_APPS</a> section in your django settings
file.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you are going to use the <a class="reference internal" href="admin.html#treebeard.admin.TreeAdmin" title="treebeard.admin.TreeAdmin"><tt class="xref py py-class docutils literal"><span class="pre">Treeadmin</span></tt></a>
class, you need to add the path to treebeard’s templates in
<a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#template-dirs">TEMPLATE_DIRS</a>.
Also you need to enable <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-request">django.core.context_processors.request</a>
in the <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors">TEMPLATE_CONTEXT_PROCESSORS</a> setting in your django settings file.</p>
</div>
</div>
<div class="section" id="basic-usage">
<h2>Basic Usage<a class="headerlink" href="#basic-usage" title="Permalink to this headline">¶</a></h2>
<p>Create a basic model for your tree. In this example we’ll use a Materialized
Path tree:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
<span class="kn">from</span> <span class="nn">treebeard.mp_tree</span> <span class="kn">import</span> <span class="n">MP_Node</span>
<span class="k">class</span> <span class="nc">Category</span><span class="p">(</span><span class="n">MP_Node</span><span class="p">):</span>
<span class="n">name</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">30</span><span class="p">)</span>
<span class="n">node_order_by</span> <span class="o">=</span> <span class="p">[</span><span class="s">'name'</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">__unicode__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="s">'Category: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
</pre></div>
</div>
<p>Run syncdb:</p>
<div class="highlight-python"><pre>python manage.py syncdb</pre>
</div>
<p>Let’s create some nodes:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">get</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">node_id</span><span class="p">:</span> <span class="n">Category</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">node_id</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">root</span> <span class="o">=</span> <span class="n">Category</span><span class="o">.</span><span class="n">add_root</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Computer Hardware'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">node</span> <span class="o">=</span> <span class="n">get</span><span class="p">(</span><span class="n">root</span><span class="o">.</span><span class="n">id</span><span class="p">)</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Memory'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">get</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">id</span><span class="p">)</span><span class="o">.</span><span class="n">add_sibling</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Hard Drives'</span><span class="p">)</span>
<span class="go"><Category: Category: Hard Drives></span>
<span class="gp">>>> </span><span class="n">get</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">id</span><span class="p">)</span><span class="o">.</span><span class="n">add_sibling</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'SSD'</span><span class="p">)</span>
<span class="go"><Category: Category: SSD></span>
<span class="gp">>>> </span><span class="n">get</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">id</span><span class="p">)</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Desktop Memory'</span><span class="p">)</span>
<span class="go"><Category: Category: Desktop Memory></span>
<span class="gp">>>> </span><span class="n">get</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">id</span><span class="p">)</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Laptop Memory'</span><span class="p">)</span>
<span class="go"><Category: Category: Laptop Memory></span>
<span class="gp">>>> </span><span class="n">get</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">id</span><span class="p">)</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Server Memory'</span><span class="p">)</span>
<span class="go"><Category: Category: Server Memory></span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Why retrieving every node again after the first operation? Because
<tt class="docutils literal"><span class="pre">django-treebeard</span></tt> uses raw queries for most write operations,
and raw queries don’t update the django objects of the db entries they
modify.</p>
</div>
<p>We just created this tree:</p>
<p class="graphviz">
<img src="_images/graphviz-4febbff6c7b8eb79ae9a104b0f04a385aa42d629.png" alt="digraph introduction_digraph {
"Computer Hardware";
"Computer Hardware" -> "Hard Drives";
"Computer Hardware" -> "Memory";
"Memory" -> "Desktop Memory";
"Memory" -> "Laptop Memory";
"Memory" -> "Server Memory";
"Computer Hardware" -> "SSD";
}" />
</p>
<dl class="docutils">
<dt>You can see the tree structure with code::</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">Category</span><span class="o">.</span><span class="n">dump_bulk</span><span class="p">()</span>
<span class="go">[{'id': 1, 'data': {'name': u'Computer Hardware'},</span>
<span class="go"> 'children': [</span>
<span class="go"> {'id': 3, 'data': {'name': u'Hard Drives'}},</span>
<span class="go"> {'id': 2, 'data': {'name': u'Memory'},</span>
<span class="go"> 'children': [</span>
<span class="go"> {'id': 5, 'data': {'name': u'Desktop Memory'}},</span>
<span class="go"> {'id': 6, 'data': {'name': u'Laptop Memory'}},</span>
<span class="go"> {'id': 7, 'data': {'name': u'Server Memory'}}]},</span>
<span class="go"> {'id': 4, 'data': {'name': u'SSD'}}]}]</span>
<span class="gp">>>> </span><span class="n">Category</span><span class="o">.</span><span class="n">get_annotated_list</span><span class="p">()</span>
<span class="go">[(<Category: Category: Computer Hardware>,</span>
<span class="go"> {'close': [], 'level': 0, 'open': True}),</span>
<span class="go"> (<Category: Category: Hard Drives>,</span>
<span class="go"> {'close': [], 'level': 1, 'open': True}),</span>
<span class="go"> (<Category: Category: Memory>,</span>
<span class="go"> {'close': [], 'level': 1, 'open': False}),</span>
<span class="go"> (<Category: Category: Desktop Memory>,</span>
<span class="go"> {'close': [], 'level': 2, 'open': True}),</span>
<span class="go"> (<Category: Category: Laptop Memory>,</span>
<span class="go"> {'close': [], 'level': 2, 'open': False}),</span>
<span class="go"> (<Category: Category: Server Memory>,</span>
<span class="go"> {'close': [0], 'level': 2, 'open': False}),</span>
<span class="go"> (<Category: Category: SSD>,</span>
<span class="go"> {'close': [0, 1], 'level': 1, 'open': False})]</span>
</pre></div>
</div>
</dd>
</dl>
<p>Read the <a class="reference internal" href="api.html#treebeard.models.Node" title="treebeard.models.Node"><tt class="xref py py-class docutils literal"><span class="pre">treebeard.models.Node</span></tt></a> API reference for detailed info.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Introduction</a><ul>
<li><a class="reference internal" href="#prerequisites">Prerequisites</a></li>
<li><a class="reference internal" href="#installation">Installation</a><ul>
<li><a class="reference internal" href="#pip-or-easy-install">pip (or easy_install)</a></li>
<li><a class="reference internal" href="#setup-py">setup.py</a></li>
<li><a class="reference internal" href="#deb-packages">.deb packages</a></li>
</ul>
</li>
<li><a class="reference internal" href="#configuration">Configuration</a></li>
<li><a class="reference internal" href="#basic-usage">Basic Usage</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">django-treebeard</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="api.html"
title="next chapter">API</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/intro.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" />
<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="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="api.html" title="API"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="django-treebeard"
>previous</a> |</li>
<li><a href="index.html">django-treebeard 2.0b1 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2008-2013, Gustavo Picon.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
|