mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Fixing stashing conflict
This commit is contained in:
parent
76d7461e43
commit
9528f971c9
18 changed files with 307 additions and 37 deletions
10
CREDITS.txt
10
CREDITS.txt
|
|
@ -0,0 +1,10 @@
|
|||
Corey Oordt github.com/coordt
|
||||
Erik Simmler github.com/tgecho
|
||||
martinogden githun.com/martinogden
|
||||
Ramiro Morales github.com/ramiro
|
||||
Evan Culver github.com/eculver
|
||||
Andrzej Herok github.com/aherok
|
||||
Jonathan Hensley
|
||||
Justin Quick github.com/justquick
|
||||
Josh Ourisman github.com/joshourisman
|
||||
Jose Soares github.com/josesoa
|
||||
|
|
@ -2,6 +2,15 @@ Django Categories grew out of our need to provide a basic hierarchical taxonomy
|
|||
|
||||
As a news site, our stories, photos, and other content get divided into "sections" and we wanted all the apps to use the same set of sections. As our needs grew, the Django Categories grew in the functionality it gave to category handling within web pages.
|
||||
|
||||
New in 0.6
|
||||
==========
|
||||
|
||||
**Class-based views**
|
||||
Works great with Django 1.3
|
||||
|
||||
**New Settings infrastructure**
|
||||
To be more like the Django project, we are migrating from individual CATEGORIES_* settings to a dictionary named ``CATEGORIES_SETTINGS``\ . Use of the previous settings will still work but will generate a ``PendingDeprecationError``\ .
|
||||
|
||||
Features of the project
|
||||
=======================
|
||||
|
||||
|
|
|
|||
|
|
@ -16,3 +16,10 @@ class CategoryFKField(ForeignKey):
|
|||
if 'to' in kwargs:
|
||||
kwargs.pop('to')
|
||||
super(CategoryFKField, self).__init__(to=Category, **kwargs)
|
||||
|
||||
try:
|
||||
from south.modelsinspector import add_introspection_rules
|
||||
add_introspection_rules([], ["^categories\.fields\.CategoryFKField"])
|
||||
add_introspection_rules([], ["^categories\.fields\.CategoryM2MField"])
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,12 +1,45 @@
|
|||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
ALLOW_SLUG_CHANGE = getattr(settings, 'CATEGORIES_ALLOW_SLUG_CHANGE', False)
|
||||
|
||||
CACHE_VIEW_LENGTH = getattr(settings, 'CATEGORIES_CACHE_VIEW_LENGTH', 3600)
|
||||
|
||||
from django.db.models import Q
|
||||
DEFAULT_RELATION_MODELS = []
|
||||
RELATION_MODELS = getattr(settings, 'CATEGORIES_RELATION_MODELS', DEFAULT_RELATION_MODELS) or []
|
||||
|
||||
CATEGORIES_SETTINGS = {
|
||||
'ALLOW_SLUG_CHANGE': False,
|
||||
'CACHE_VIEW_LENGTH': 0,
|
||||
'RELATION_MODELS': [],
|
||||
'M2M_REGISTRY': [],
|
||||
'FK_REGISTRY': []
|
||||
}
|
||||
|
||||
CATEGORIES_SETTINGS.update(getattr(settings, 'CATEGORIES_SETTINGS', {}))
|
||||
|
||||
if hasattr(settings, 'CATEGORIES_ALLOW_SLUG_CHANGE'):
|
||||
warnings.warn(
|
||||
"settings.CATEGORIES_ALLOW_SLUG_CHANGE is deprecated; use settings.CATEGORIES_SETTINGS instead.",
|
||||
DeprecationWarning
|
||||
)
|
||||
ALLOW_SLUG_CHANGE = getattr(settings, 'CATEGORIES_ALLOW_SLUG_CHANGE')
|
||||
else:
|
||||
ALLOW_SLUG_CHANGE = CATEGORIES_SETTINGS['ALLOW_SLUG_CHANGE']
|
||||
|
||||
if hasattr(settings, 'CATEGORIES_CACHE_VIEW_LENGTH'):
|
||||
warnings.warn(
|
||||
"settings.CATEGORIES_CACHE_VIEW_LENGTH is deprecated; use settings.CATEGORIES_SETTINGS instead.",
|
||||
DeprecationWarning
|
||||
)
|
||||
CACHE_VIEW_LENGTH = getattr(settings, 'CATEGORIES_CACHE_VIEW_LENGTH')
|
||||
else:
|
||||
CACHE_VIEW_LENGTH = CATEGORIES_SETTINGS['CACHE_VIEW_LENGTH']
|
||||
|
||||
if hasattr(settings, 'CATEGORIES_RELATION_MODELS'):
|
||||
warnings.warn(
|
||||
"settings.CATEGORIES_RELATION_MODELS is deprecated; use settings.CATEGORIES_SETTINGS instead.",
|
||||
DeprecationWarning
|
||||
)
|
||||
RELATION_MODELS = getattr(settings, 'CATEGORIES_RELATION_MODELS')
|
||||
else:
|
||||
RELATION_MODELS = CATEGORIES_SETTINGS['RELATION_MODELS']
|
||||
|
||||
RELATIONS = [Q(app_label=al, model=m) for al, m in [x.split('.') for x in RELATION_MODELS]]
|
||||
|
||||
# For assigning a thumbnail to a category
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ Contents:
|
|||
usage
|
||||
registering_models
|
||||
templatetags
|
||||
reference/index
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
|
|
|||
|
|
@ -3,6 +3,93 @@ Registering Models
|
|||
==================
|
||||
|
||||
|
||||
Registering models in settings.py
|
||||
=================================
|
||||
|
||||
It is nice to not have to modify the code of applications to add a relation to categories. You can therefore do all the registering in ``settings.py``\ . For example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
CATEGORIES_SETTINGS = {
|
||||
'FK_REGISTRY': {
|
||||
'app.AModel': 'category',
|
||||
'app.MyModel': (
|
||||
'primary_category',
|
||||
{'name': 'secondary_category', 'related_name': 'mymodel_sec_cat'}, )
|
||||
},
|
||||
'M2M_REGISTRY': {
|
||||
'app.AModel': 'categories',
|
||||
'app.MyModel': ('other_categories', 'more_categories', ),
|
||||
}
|
||||
}
|
||||
|
||||
The ``FK_REGISTRY`` is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings or dictionaries specifying the necessary information for each field.
|
||||
|
||||
The ``M2M_REGISTRY`` is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings specifying the necessary information for each field.
|
||||
|
||||
|
||||
Registering one Category field to model
|
||||
***************************************
|
||||
|
||||
The simplest way is to specify the name of the field, such as:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
CATEGORIES_SETTINGS = {
|
||||
'FK_REGISTRY': {
|
||||
'app.AModel': 'category'
|
||||
}
|
||||
}
|
||||
|
||||
This is equivalent to adding the following the ``AModel`` of ``app``\ :
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
category = models.ForeignKey(Category)
|
||||
|
||||
|
||||
If you want more control over the new field, you can use a dictionary and pass other ``ForeignKey`` options. The ``name`` key is required:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
CATEGORIES_SETTINGS = {
|
||||
'FK_REGISTRY': {
|
||||
'app.AModel': {'name': 'category', 'related_name': 'amodel_cats'}
|
||||
}
|
||||
}
|
||||
|
||||
This is equivalent to adding the following the ``AModel`` of ``app``\ :
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
category = models.ForeignKey(Category, related_name='amodel_cats')
|
||||
|
||||
Registering two or more Category fields to a Model
|
||||
**************************************************
|
||||
|
||||
When you want more than one relation to ``Category``\ , all but one of the fields must specify a ``related_name`` to avoid conflicts, like so:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
CATEGORIES_SETTINGS = {
|
||||
'FK_REGISTRY': {
|
||||
'app.MyModel': (
|
||||
'primary_category',
|
||||
{'name': 'secondary_category', 'related_name': 'mymodel_sec_cat'}, )
|
||||
},
|
||||
|
||||
Registering one or more Many-to-Many Category fields to a Model
|
||||
***************************************************************
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
CATEGORIES_SETTINGS = {
|
||||
'M2M_REGISTRY': {
|
||||
'app.AModel': 'categories',
|
||||
'app.MyModel': ('other_categories', 'more_categories', ),
|
||||
}
|
||||
}
|
||||
|
||||
Registering a many-to-one relationship
|
||||
======================================
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Sphinx build info version 1
|
||||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
|
||||
config: e4eb74933f8c18cbcf27c5697f36ee4a
|
||||
config: 071e7273e6f47dab6004e15916a31efa
|
||||
tags: fbb0d17656682115ca4d033fb2f83ba1
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ Contents:
|
|||
usage
|
||||
registering_models
|
||||
templatetags
|
||||
reference/index
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
|
|
|||
|
|
@ -3,6 +3,68 @@ Registering Models
|
|||
==================
|
||||
|
||||
|
||||
Registering models in settings.py
|
||||
=================================
|
||||
|
||||
It is nice to not have to modify the code of applications to add a relation to categories. You can therefore do all the registering in ``settings.py``\ . For example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
CATEGORIES_SETTINGS = {
|
||||
'FK_REGISTRY': {
|
||||
'app.AModel': 'category',
|
||||
'app.MyModel': (
|
||||
'primary_category',
|
||||
{'name': 'secondary_category', 'related_name': 'mymodel_sec_cat'}, )
|
||||
},
|
||||
'M2M_REGISTRY': {
|
||||
'app.AModel': 'categories',
|
||||
'app.MyModel': ('other_categories', 'more_categories', ),
|
||||
}
|
||||
}
|
||||
|
||||
The ``FK_REGISTRY`` is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings or dictionaries specifying the necessary information for each field.
|
||||
|
||||
The ``M2M_REGISTRY`` is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings specifying the necessary information for each field.
|
||||
|
||||
|
||||
Registering One Category Field
|
||||
******************************
|
||||
|
||||
The simplest way is to specify the name of the field, such as:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
CATEGORIES_SETTINGS = {
|
||||
'FK_REGISTRY': {
|
||||
'app.AModel': 'category'
|
||||
}
|
||||
}
|
||||
|
||||
This is equivalent to adding the following the ``AModel`` of ``app``\ :
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
category = models.ForeignKey(Category)
|
||||
|
||||
|
||||
If you want more control over the new field, you can use a dictionary and pass other ``ForeignKey`` options:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
CATEGORIES_SETTINGS = {
|
||||
'FK_REGISTRY': {
|
||||
'app.AModel': {'name': 'category', 'related_name': 'amodel_cats'}
|
||||
}
|
||||
}
|
||||
|
||||
This is equivalent to adding the following the ``AModel`` of ``app``\ :
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
category = models.ForeignKey(Category, related_name='amodel_cats')
|
||||
|
||||
|
||||
Registering a many-to-one relationship
|
||||
======================================
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Index — Django Categories v0.4.8 documentation</title>
|
||||
<title>Index — Django Categories v0.6beta1 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.4.8',
|
||||
VERSION: '0.6beta1',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,11 +21,11 @@
|
|||
<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.4.8 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.6beta1 documentation" href="index.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.4.8 documentation</p>
|
||||
<p>Django Categories v0.6beta1 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Index</h1></div>
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
<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="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Getting Started — Django Categories v0.4.8 documentation</title>
|
||||
<title>Getting Started — Django Categories v0.6beta1 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.4.8',
|
||||
VERSION: '0.6beta1',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,13 +21,13 @@
|
|||
<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.4.8 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.6beta1 documentation" href="index.html" />
|
||||
<link rel="next" title="Using categories in templates" href="usage.html" />
|
||||
<link rel="prev" title="Django Categories v|version| documentation!" href="index.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.4.8 documentation</p>
|
||||
<p>Django Categories v0.6beta1 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Getting Started</h1></div>
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Django Categories v|version| documentation! — Django Categories v0.4.8 documentation</title>
|
||||
<title>Django Categories v|version| documentation! — Django Categories v0.6beta1 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.4.8',
|
||||
VERSION: '0.6beta1',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,12 +21,12 @@
|
|||
<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.4.8 documentation" href="#" />
|
||||
<link rel="top" title="Django Categories v0.6beta1 documentation" href="#" />
|
||||
<link rel="next" title="Getting Started" href="getting_started.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.4.8 documentation</p>
|
||||
<p>Django Categories v0.6beta1 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Django Categories v|version| documentation!</h1></div>
|
||||
|
|
@ -47,6 +47,7 @@
|
|||
<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="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
<h3>This Page</h3>
|
||||
|
|
@ -95,6 +96,7 @@
|
|||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="registering_models.html">Registering Models</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="registering_models.html#registering-models-in-settings-py">Registering models in settings.py</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="registering_models.html#registering-a-many-to-one-relationship">Registering a many-to-one relationship</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="registering_models.html#registering-a-many-to-many-relationship">Registering a many-to-many relationship</a></li>
|
||||
</ul>
|
||||
|
|
@ -107,6 +109,10 @@
|
|||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#breadcrumbs-tag">breadcrumbs tag</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="reference/settings.html">Settings</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="indices-and-tables">
|
||||
|
|
|
|||
BIN
docs/objects.inv
BIN
docs/objects.inv
Binary file not shown.
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Registering Models — Django Categories v0.4.8 documentation</title>
|
||||
<title>Registering Models — Django Categories v0.6beta1 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.4.8',
|
||||
VERSION: '0.6beta1',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,12 +21,13 @@
|
|||
<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.4.8 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.6beta1 documentation" href="index.html" />
|
||||
<link rel="next" title="Template Tags" href="templatetags.html" />
|
||||
<link rel="prev" title="Using categories in templates" href="usage.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.4.8 documentation</p>
|
||||
<p>Django Categories v0.6beta1 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Registering Models</h1></div>
|
||||
|
|
@ -34,6 +35,7 @@
|
|||
<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="templatetags.html" title="Template Tags" accesskey="N">next</a></div>
|
||||
<div class="headerButton"><a href="usage.html" title="Using categories in templates" accesskey="P">previous</a></div>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
@ -46,10 +48,13 @@
|
|||
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="usage.html">Using categories in templates</a></li>
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="">Registering Models</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#registering-models-in-settings-py">Registering models in settings.py</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#registering-a-many-to-one-relationship">Registering a many-to-one relationship</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#registering-a-many-to-many-relationship">Registering a many-to-many relationship</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
<h3>This Page</h3>
|
||||
|
|
@ -86,6 +91,53 @@
|
|||
|
||||
<div class="section" id="registering-models">
|
||||
<h1>Registering Models<a class="headerlink" href="#registering-models" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="section" id="registering-models-in-settings-py">
|
||||
<h2>Registering models in settings.py<a class="headerlink" href="#registering-models-in-settings-py" title="Permalink to this headline">¶</a></h2>
|
||||
<p>It is nice to not have to modify the code of applications to add a relation to categories. You can therefore do all the registering in <tt class="docutils literal"><span class="pre">settings.py</span></tt>. For example:</p>
|
||||
<div class="highlight-python"><div class="highlight"><pre><span class="n">CATEGORIES_SETTINGS</span> <span class="o">=</span> <span class="p">{</span>
|
||||
<span class="s">'FK_REGISTRY'</span><span class="p">:</span> <span class="p">{</span>
|
||||
<span class="s">'app.AModel'</span><span class="p">:</span> <span class="s">'category'</span><span class="p">,</span>
|
||||
<span class="s">'app.MyModel'</span><span class="p">:</span> <span class="p">(</span>
|
||||
<span class="s">'primary_category'</span><span class="p">,</span>
|
||||
<span class="p">{</span><span class="s">'name'</span><span class="p">:</span> <span class="s">'secondary_category'</span><span class="p">,</span> <span class="s">'related_name'</span><span class="p">:</span> <span class="s">'mymodel_sec_cat'</span><span class="p">},</span> <span class="p">)</span>
|
||||
<span class="p">},</span>
|
||||
<span class="s">'M2M_REGISTRY'</span><span class="p">:</span> <span class="p">{</span>
|
||||
<span class="s">'app.AModel'</span><span class="p">:</span> <span class="s">'categories'</span><span class="p">,</span>
|
||||
<span class="s">'app.MyModel'</span><span class="p">:</span> <span class="p">(</span><span class="s">'other_categories'</span><span class="p">,</span> <span class="s">'more_categories'</span><span class="p">,</span> <span class="p">),</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The <tt class="docutils literal"><span class="pre">FK_REGISTRY</span></tt> is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings or dictionaries specifying the necessary information for each field.</p>
|
||||
<p>The <tt class="docutils literal"><span class="pre">M2M_REGISTRY</span></tt> is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings specifying the necessary information for each field.</p>
|
||||
<div class="section" id="registering-one-category-field">
|
||||
<h3>Registering One Category Field<a class="headerlink" href="#registering-one-category-field" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The simplest way is to specify the name of the field, such as:</p>
|
||||
<div class="highlight-python"><div class="highlight"><pre><span class="n">CATEGORIES_SETTINGS</span> <span class="o">=</span> <span class="p">{</span>
|
||||
<span class="s">'FK_REGISTRY'</span><span class="p">:</span> <span class="p">{</span>
|
||||
<span class="s">'app.AModel'</span><span class="p">:</span> <span class="s">'category'</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>This is equivalent to adding the following the <tt class="docutils literal"><span class="pre">AModel</span></tt> of <tt class="docutils literal"><span class="pre">app</span></tt>:</p>
|
||||
<div class="highlight-python"><div class="highlight"><pre><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="n">Category</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>If you want more control over the new field, you can use a dictionary and pass other <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> options:</p>
|
||||
<div class="highlight-python"><div class="highlight"><pre><span class="n">CATEGORIES_SETTINGS</span> <span class="o">=</span> <span class="p">{</span>
|
||||
<span class="s">'FK_REGISTRY'</span><span class="p">:</span> <span class="p">{</span>
|
||||
<span class="s">'app.AModel'</span><span class="p">:</span> <span class="p">{</span><span class="s">'name'</span><span class="p">:</span> <span class="s">'category'</span><span class="p">,</span> <span class="s">'related_name'</span><span class="p">:</span> <span class="s">'amodel_cats'</span><span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>This is equivalent to adding the following the <tt class="docutils literal"><span class="pre">AModel</span></tt> of <tt class="docutils literal"><span class="pre">app</span></tt>:</p>
|
||||
<div class="highlight-python"><div class="highlight"><pre><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="n">Category</span><span class="p">,</span> <span class="n">related_name</span><span class="o">=</span><span class="s">'amodel_cats'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="registering-a-many-to-one-relationship">
|
||||
<h2>Registering a many-to-one relationship<a class="headerlink" href="#registering-a-many-to-one-relationship" title="Permalink to this headline">¶</a></h2>
|
||||
<p>To create a many-to-one relationship (foreign key) between a model and Django Categories, you register your model with the <tt class="docutils literal"><span class="pre">register_fk</span></tt> function.</p>
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Search — Django Categories v0.4.8 documentation</title>
|
||||
<title>Search — Django Categories v0.6beta1 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.4.8',
|
||||
VERSION: '0.6beta1',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<script type="text/javascript" src="_static/searchtools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.4.8 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.6beta1 documentation" href="index.html" />
|
||||
<script type="text/javascript">
|
||||
jQuery(function() { Search.loadIndex("searchindex.js"); });
|
||||
</script>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.4.8 documentation</p>
|
||||
<p>Django Categories v0.6beta1 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Search</h1></div>
|
||||
|
|
@ -51,6 +51,7 @@
|
|||
<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="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Search.setIndex({objects:{"":{register_m2m:[2,0,1],register_fk:[2,0,1]}},terms:{represent:0,all:4,sci:0,over:0,becaus:3,syntax:4,comma:0,follow:0,secondary_categori:2,children:4,paramet:2,hierarch:[],categori:[0,1,2,3,4],should:0,add:[0,3],valid:0,dict:0,templat:[0,1,4],under:0,modul:1,tree_info:0,descend:0,child1:4,child2:4,child3:4,"return":4,greater:0,get:[1,3],fals:0,extra_arg:2,mechan:[],mymodel_sec_set:[],"import":[0,2,3],field_nam:2,eventu:3,name:[0,2,3],level:0,list:[0,4],html:4,iter:[0,4],separ:[0,4],item:0,contain:0,unicod:0,page:1,set:4,some:2,around:0,sampl:0,connect:[1,3],pass:2,happen:3,even:3,index:1,what:3,appear:0,though:3,content:[0,1],version:1,between:2,"new":0,method:3,attribut:3,grandpar:4,kei:[0,2],gener:0,given:0,display_drilldown_as_ul:[1,4],dictionari:2,"super":[],addit:3,both:3,about:0,last:0,wai:3,current:0,foreign:2,filter:[0,1],related_nam:2,new_level:0,mani:[1,2,3],display_path_as_ul:[1,4],first:0,simpli:3,render:4,extra:[0,2],app:[],mymodel_sec_cat:2,href:4,subcategori:3,famili:4,respect:3,storag:3,your:[1,2,3],category_obj:4,would:[0,3],start:[0,1,3],top:[3,4],regist:[1,2],two:[0,3],empti:0,next:0,avail:0,few:3,immedi:[0,4],more:2,"function":2,option:[0,2,4],relationship:[1,2,3],tupl:0,search:1,specifi:[0,2,4],argument:[0,2,4],link:2,indic:1,child:4,closed_level:0,"true":0,than:[0,2],retriev:4,provid:0,tree:[0,3],structur:0,alter:4,below:0,can:[0,3,4],foreignkei:[2,3],otherwis:0,root:0,document:1,featur:0,have:[2,3],creat:[2,3],get_top_level_categori:[1,4],primary_categori:2,doesn:2,manytomanyfield:2,tag:[0,1,4],right:0,want:2,tabl:1,need:3,sever:3,string:4,parent:[0,4],end:0,welcom:[],alphabet:4,register_fk:[2,3],detail:0,same:[0,3],field:2,book:0,futur:0,which:0,you:[2,3,4],ancestor:[0,4],node:0,thi:0,clash:2,"default":2,after:0,category_tag:0,breadcrumb:[1,4],extra_param:2,data:[],"class":2,ul_tre:4,dystopian:0,get_category_drilldown:[1,4],mymodel:[2,3],django:[1,2,3],inform:0,exampl:[0,2,3,4],allow:2,time:3,model:[1,2,3],register_m2m:[2,3],order:0},objtypes:{"0":"py:function"},titles:["Using categories in templates","Django Categories v|version| documentation!","Registering Models","Getting Started","Template Tags"],objnames:{"0":"Python function"},filenames:["usage","index","registering_models","getting_started","templatetags"]})
|
||||
Search.setIndex({objects:{"":{register_fk:[2,0,1],register_m2m:[2,0,1]}},terms:{represent:5,all:[2,3],code:2,sci:5,over:[5,2],becaus:6,syntax:3,comma:5,follow:[5,2],secondary_categori:2,children:3,paramet:2,hierarch:[],categori:[5,0,2,3,6],other_categori:2,should:5,add:[5,2,6],valid:5,dict:5,under:5,therefor:2,app:2,tree_info:5,futur:5,child1:3,child2:3,child3:3,"return":3,greater:5,amodel:2,get:[0,6],fals:5,extra_arg:2,between:2,mechan:[],mymodel_sec_set:[],"new":[5,2],field_nam:2,string:[2,3],ancestor:[5,3],name:[5,2,6],doesn:2,level:5,list:[5,3],iter:[5,3],amodel_cat:2,separ:[5,3],item:5,necessari:2,each:2,unicod:5,refer:[0,4],page:0,set:[0,1,2,3,4],some:2,sampl:5,connect:[0,6],pass:2,happen:6,even:6,index:0,what:6,appear:5,content:[5,0],version:0,simplest:2,"import":[5,2,6],method:6,attribut:6,grandpar:3,kei:[5,2],whose:2,gener:5,contain:5,category_obj:3,fk_registri:2,dictionari:2,"super":[],valu:2,addit:6,both:6,about:5,categories_set:2,last:5,would:[5,6],current:5,display_drilldown_as_ul:[0,3],foreign:2,filter:[5,0],related_nam:2,new_level:5,mani:[0,2,6],display_path_as_ul:[0,3],other:2,first:5,simpli:6,render:3,extra:[5,2],appli:[],modul:0,mymodel_sec_cat:2,href:3,subcategori:6,famili:3,clash:2,respect:6,storag:6,your:[0,2,6],given:5,wai:[2,6],few:6,modifi:2,top:[3,6],regist:[0,2],two:[5,6],empti:5,next:5,avail:5,start:[5,0,6],time:6,immedi:[5,3],more:2,"function":2,field:2,option:[5,2,3],relationship:[0,2,6],tupl:[5,2],relat:2,search:0,specifi:[5,2,3],primary_categori:2,link:2,indic:0,child:3,closed_level:5,"true":5,than:[5,2],retriev:3,provid:5,tree:[5,6],structur:5,alter:3,below:5,can:[5,2,3,6],foreignkei:[2,6],otherwis:5,root:5,document:0,control:2,featur:5,want:2,creat:[2,6],applic:2,get_top_level_categori:[0,3],argument:[5,2,3],templat:[5,0,3],manytomanyfield:2,tag:[5,0,3],right:5,have:[2,6],tabl:0,need:6,sever:6,around:5,parent:[5,3],end:5,welcom:[],equival:2,titl:[],more_categori:2,register_fk:[2,6],detail:5,same:[5,6],"default":2,html:3,descend:5,which:[5,2],m2m_registri:2,you:[2,3,6],eventu:6,nice:2,node:5,allow:2,book:5,though:6,after:5,category_tag:5,breadcrumb:[0,3],extra_param:2,data:[],"class":2,ul_tre:3,dystopian:5,get_category_drilldown:[0,3],mymodel:[2,6],django:[0,2,6],inform:[5,2],exampl:[5,2,3,6],thi:[5,2],alphabet:3,model:[0,2,6],register_m2m:[2,6],order:5},objtypes:{"0":"py:function"},titles:["Django Categories v|version| documentation!","Settings","Registering Models","Template Tags","Reference","Using categories in templates","Getting Started"],objnames:{"0":"Python function"},filenames:["index","reference/settings","registering_models","templatetags","reference/index","usage","getting_started"]})
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Template Tags — Django Categories v0.4.8 documentation</title>
|
||||
<title>Template Tags — Django Categories v0.6beta1 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.4.8',
|
||||
VERSION: '0.6beta1',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,12 +21,12 @@
|
|||
<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.4.8 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.6beta1 documentation" href="index.html" />
|
||||
<link rel="prev" title="Registering Models" href="registering_models.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.4.8 documentation</p>
|
||||
<p>Django Categories v0.6beta1 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Template Tags</h1></div>
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Using categories in templates — Django Categories v0.4.8 documentation</title>
|
||||
<title>Using categories in templates — Django Categories v0.6beta1 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.4.8',
|
||||
VERSION: '0.6beta1',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,13 +21,13 @@
|
|||
<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.4.8 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.6beta1 documentation" href="index.html" />
|
||||
<link rel="next" title="Registering Models" href="registering_models.html" />
|
||||
<link rel="prev" title="Getting Started" href="getting_started.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.4.8 documentation</p>
|
||||
<p>Django Categories v0.6beta1 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Using categories in templates</h1></div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue