mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-17 06:40:25 +00:00
165 lines
No EOL
8.5 KiB
HTML
165 lines
No EOL
8.5 KiB
HTML
|
|
<!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>Getting Started — Django Categories v0.8.2 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: '0.8.2',
|
|
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 Categories v0.8.2 documentation" href="index.html" />
|
|
<link rel="next" title="Using categories in templates" href="usage.html" />
|
|
<link rel="prev" title="Django Categories v 0.8.2" href="index.html" />
|
|
</head>
|
|
<body>
|
|
<div id="docstitle">
|
|
<p>Django Categories v0.8.2 documentation</p>
|
|
</div>
|
|
<div id="header">
|
|
<div id="title"><h1>Getting Started</h1></div>
|
|
<ul id="headerButtons">
|
|
<li id="toc_button"><div class="headerButton"><a href="#">Table of Contents</a></div></li>
|
|
<li id="page_buttons">
|
|
<div class="headerButton"><a href="genindex.html" title="General Index" accesskey="I">index</a></div>
|
|
<div class="headerButton"><a href="usage.html" title="Using categories in templates" accesskey="N">next</a></div>
|
|
<div class="headerButton"><a href="index.html" title="Django Categories v 0.8.2" accesskey="P">previous</a></div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
<ul><li class="toctree-l1"><a href="index.html">Main Page</a></li></ul>
|
|
<ul class="current">
|
|
<li class="toctree-l1 current"><a class="current reference internal" href="">Getting Started</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="#connecting-your-model-with-django-categories">Connecting your model with Django-Categories</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="usage.html">Using categories in templates</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="registering_models.html">Registering Models</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="adding_the_fields.html">Adding the fields to the database</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
|
</ul>
|
|
|
|
<h3>This Page</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="_sources/getting_started.txt"
|
|
rel="nofollow">Show Source</a></li>
|
|
</ul>
|
|
<div id="searchbox" style="display: none">
|
|
|
|
<form class="search" action="search.html" method="get">
|
|
<div class="search-wrapper">
|
|
<span class="search-left"></span>
|
|
<input class="prettysearch" type="text" name="q" size="18" />
|
|
<span class="search-right"> </span>
|
|
</div>
|
|
<input type="submit" value="Search" class="searchbutton" />
|
|
<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="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<div class="section" id="getting-started">
|
|
<h1>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h1>
|
|
<p>You can use Django Categories in two ways:</p>
|
|
<ol class="arabic">
|
|
<li><p class="first">As storage for one tree of categories, e.g.:</p>
|
|
<div class="highlight-python"><pre>Top Category 1
|
|
Subcategory 1-1
|
|
Subcategory 1-2
|
|
subcategory 1-2-1
|
|
Top Category 2
|
|
Subcategory 2-1</pre>
|
|
</div>
|
|
</li>
|
|
<li><p class="first">As a storage of several trees of categories, e.g.:</p>
|
|
<div class="highlight-python"><pre>Model 1
|
|
Category 1
|
|
Subcategory 1-1
|
|
Subcategory 1-2
|
|
subcategory 1-2-1
|
|
Category 2
|
|
Subcategory 2-1
|
|
Model 2
|
|
Category 3
|
|
Subcategory 3-1
|
|
Subcategory 3-2
|
|
subcategory 3-2-1
|
|
Category 4
|
|
Subcategory 4-1</pre>
|
|
</div>
|
|
</li>
|
|
</ol>
|
|
<p>You can’t do it as both at the same time, though.</p>
|
|
<div class="section" id="connecting-your-model-with-django-categories">
|
|
<h2>Connecting your model with Django-Categories<a class="headerlink" href="#connecting-your-model-with-django-categories" title="Permalink to this headline">¶</a></h2>
|
|
<p>There are two ways to add Category fields to an application. If you are in control of the code (it’s your application) or you are willing to take control of the code (fork someone else’s app) you can make a <a class="reference internal" href="#hard-coded-connection"><em>Hard Coded Connection</em></a>.</p>
|
|
<p>For 3rd-party apps or even your own apps that you don’t wish to add Django-Categories as a dependency, you can configure a <a class="reference internal" href="#lazy-connection"><em>Lazy Connection</em></a>.</p>
|
|
<div class="section" id="hard-coded-connection">
|
|
<span id="id1"></span><h3>Hard Coded Connection<a class="headerlink" href="#hard-coded-connection" title="Permalink to this headline">¶</a></h3>
|
|
<p>Hard coded connections are done in the exact same way you handle any other foreign key or many-to-many relations to a model.</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="k">class</span> <span class="nc">MyModel</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</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">100</span><span class="p">)</span>
|
|
<span class="n">category</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">'categories.Category'</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Don’t forget to add the field or fields to your <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> class as well.</p>
|
|
</div>
|
|
<div class="section" id="lazy-connection">
|
|
<span id="id2"></span><h3>Lazy Connection<a class="headerlink" href="#lazy-connection" title="Permalink to this headline">¶</a></h3>
|
|
<p>Lazy connections are done through configuring Django Categories in the project’s <tt class="docutils literal"><span class="pre">settings.py</span></tt> file. When the project starts up, the configured fields are dynamically added to the configured models and admin.</p>
|
|
<p>If you do this before you have created the database (before you ran <tt class="docutils literal"><span class="pre">manage.py</span> <span class="pre">syncdb</span></tt>), the fields will also be in the tables. If you do this after you have already created all the tables, you can run <tt class="docutils literal"><span class="pre">manage.py</span> <span class="pre">add_category_fields</span></tt> to create the fields (this requires Django South to be installed).</p>
|
|
<p>You add a many-to-one or many-to-many relationship with Django Categories using the <tt class="docutils literal"><span class="pre">CATEGORIES_SETTINGS['FK_REGISTRY']</span></tt> and <tt class="docutils literal"><span class="pre">CATEGORIES_SETTINGS['M2M_REGISTRY']</span></tt> settings respectively. For more information see <a class="reference internal" href="registering_models.html#registering-models"><em>Registering Models</em></a>.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="footer">
|
|
<p>
|
|
© Copyright 2010, CoreyOordt.
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
|
|
</p>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div id="breadcrumbs">
|
|
Getting Started
|
|
</ul>
|
|
</div>
|
|
<script type="text/javascript" charset="utf-8" src="_static/toc.js"></script>
|
|
</body>
|
|
</html> |