<liclass="toctree-l2"><aclass="reference internal"href="#connecting-your-model-with-django-categories">Connecting your model with Django-Categories</a></li>
</ul>
</li>
<liclass="toctree-l1"><aclass="reference internal"href="usage.html">Using categories in templates</a></li>
<h2>Connecting your model with Django-Categories<aclass="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 <aclass="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 <aclass="reference internal"href="#lazy-connection"><em>Lazy Connection</em></a>.</p>
<divclass="section"id="hard-coded-connection">
<spanid="id1"></span><h3>Hard Coded Connection<aclass="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>
<p>Don’t forget to add the field or fields to your <ttclass="docutils literal"><spanclass="pre">ModelAdmin</span></tt> class as well.</p>
</div>
<divclass="section"id="lazy-connection">
<spanid="id2"></span><h3>Lazy Connection<aclass="headerlink"href="#lazy-connection"title="Permalink to this headline">¶</a></h3>
<p>Lazy connections are done through configuring Django Categories in the project’s <ttclass="docutils literal"><spanclass="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 <ttclass="docutils literal"><spanclass="pre">manage.py</span><spanclass="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 <ttclass="docutils literal"><spanclass="pre">manage.py</span><spanclass="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 <ttclass="docutils literal"><spanclass="pre">CATEGORIES_SETTINGS['FK_REGISTRY']</span></tt> and <ttclass="docutils literal"><spanclass="pre">CATEGORIES_SETTINGS['M2M_REGISTRY']</span></tt> settings respectively. For more information see <aclass="reference internal"href="registering_models.html#registering-models"><em>Registering Models</em></a>.</p>