Updated documentation for 1.0b1

This commit is contained in:
Corey Oordt 2012-02-08 11:23:58 -05:00
parent 97c14b19ea
commit 09175c7ef4
44 changed files with 1530 additions and 434 deletions

View file

@ -2,6 +2,28 @@ 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. 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 1.0
==========
**Abstract Base Class for generic hierarchical category models**
When you want a multiple types of categories and don't want them all part of the same model, you can now easily create new models by subclassing ``CategoryBase``. You can also add additional metadata as necessary.
Your model's can subclass ``CategoryBaseAdminForm`` and ``CategoryBaseAdmin`` to get the hierarchical management in the admin.
See the docs for more information.
**Increased the default caching time on views**
The default setting for ``CACHE_VIEW_LENGTH`` was ``0``, which means it would tell the browser to *never* cache the page. It is now ``600``, which is the default for `CACHE_MIDDLEWARE_SECONDS <https://docs.djangoproject.com/en/1.3/ref/settings/#cache-middleware-seconds>`_
**Updated for use with Django-MPTT 0.5**
Just a few tweaks.
**Initial compatibility with Django 1.4**
More is coming, but at least it works.
**Slug transliteration for non-ASCII characters**
A new setting, ``SLUG_TRANSLITERATOR``, allows you to specify a function for converting the non-ASCII characters to ASCII characters before the slugification. Works great with `Unidecode <http://pypi.python.org/pypi/Unidecode>`_.
Updated in 0.8.8 Updated in 0.8.8
================ ================

View file

@ -532,6 +532,10 @@ pre {
padding: 10px; padding: 10px;
} }
td.linenos {
width: 2em;
}
td.linenos pre { td.linenos pre {
padding: 5px 0px; padding: 5px 0px;
border: 0; border: 0;
@ -539,14 +543,23 @@ td.linenos pre {
color: #aaa; color: #aaa;
} }
td.code {
}
table.highlighttable { table.highlighttable {
margin-left: 0.5em; margin-left: 0.5em;
width: 100%;
} }
table.highlighttable td { table.highlighttable td {
padding: 0 0.5em 0 0.5em; padding: 0 0.5em 0 0.5em;
} }
table.highlighttable td.linenos {
text-align: right;
width: 1.5em;
padding-right: 0;
}
tt { tt {
font-family:"Bitstream Vera Sans Mono",Monaco,"Lucida Console",Courier,Consolas,monospace; font-family:"Bitstream Vera Sans Mono",Monaco,"Lucida Console",Courier,Consolas,monospace;

View file

@ -0,0 +1,9 @@
from categories.models import CategoryBase
class SimpleCategory(CategoryBase):
"""
A simple of catgorizing example
"""
class Meta:
verbose_name_plural = 'simple categories'

View file

@ -0,0 +1,14 @@
from django.contrib import admin
from categories.admin import CategoryBaseAdmin, CategoryBaseAdminForm
from .models import SimpleCategory
class SimpleCategoryAdminForm(CategoryBaseAdminForm):
class Meta:
model = SimpleCategory
class SimpleCategoryAdmin(CategoryBaseAdmin):
form = SimpleCategoryAdminForm
admin.site.register(SimpleCategory, SimpleCategoryAdmin)

View file

@ -0,0 +1,29 @@
class Category(CategoryBase):
thumbnail = models.FileField(
upload_to=THUMBNAIL_UPLOAD_PATH,
null=True, blank=True,
storage=STORAGE(),)
thumbnail_width = models.IntegerField(blank=True, null=True)
thumbnail_height = models.IntegerField(blank=True, null=True)
order = models.IntegerField(default=0)
alternate_title = models.CharField(
blank=True,
default="",
max_length=100,
help_text="An alternative title to use on pages with this category.")
alternate_url = models.CharField(
blank=True,
max_length=200,
help_text="An alternative URL to use instead of the one derived from "
"the category hierarchy.")
description = models.TextField(blank=True, null=True)
meta_keywords = models.CharField(
blank=True,
default="",
max_length=255,
help_text="Comma-separated keywords for search engines.")
meta_extra = models.TextField(
blank=True,
default="",
help_text="(Advanced) Any additional HTML to be placed verbatim "
"in the &lt;head&gt;")

View file

@ -0,0 +1,15 @@
def save(self, *args, **kwargs):
if self.thumbnail:
from django.core.files.images import get_image_dimensions
import django
if django.VERSION[1] < 2:
width, height = get_image_dimensions(self.thumbnail.file)
else:
width, height = get_image_dimensions(self.thumbnail.file, close=True)
else:
width, height = None, None
self.thumbnail_width = width
self.thumbnail_height = height
super(Category, self).save(*args, **kwargs)

View file

@ -0,0 +1,5 @@
class Meta(CategoryBase.Meta):
verbose_name_plural = 'categories'
class MPTTMeta:
order_insertion_by = ('order', 'name')

View file

@ -0,0 +1,9 @@
class CategoryAdminForm(CategoryBaseAdminForm):
class Meta:
model = Category
def clean_alternate_title(self):
if self.instance is None or not self.cleaned_data['alternate_title']:
return self.cleaned_data['name']
else:
return self.cleaned_data['alternate_title']

View file

@ -0,0 +1,17 @@
class CategoryAdmin(CategoryBaseAdmin):
form = CategoryAdminForm
list_display = ('name', 'alternate_title', 'active')
fieldsets = (
(None, {
'fields': ('parent', 'name', 'thumbnail', 'active')
}),
('Meta Data', {
'fields': ('alternate_title', 'alternate_url', 'description',
'meta_keywords', 'meta_extra'),
'classes': ('collapse',),
}),
('Advanced', {
'fields': ('order', 'slug'),
'classes': ('collapse',),
}),
)

View file

@ -0,0 +1,58 @@
.. _creating_custom_categories:
==========================
Creating Custom Categories
==========================
Django Categories isn't just for using a single category model. It allows you to create your own custom category-like models with as little or much customization as you need.
Name only
=========
For many cases, you want a simple user-managed lookup table. You can do this with just a little bit of code. The resulting model will include name, slug and active fields and a hierarchical admin.
#. Create a model that subclasses :py:class:`CategoryBase`
.. literalinclude:: code_examples/custom_categories1.py
:linenos:
#. For the Django admin, create a subclass of :py:class:`CategoryBaseAdminForm`. Create an internal class called :py:class:`Meta` and assign the attribute ``model`` to your model (see line 9 in the example).
.. literalinclude:: code_examples/custom_categories2.py
:linenos:
#. Create a subclass of CategoryBaseAdmin and assign ``form`` attribute the class created above (see line 12 in the above example).
#. Register your model and custom model admin class.
Name and other data
===================
Sometimes you need more functionality, such as extra metadata and custom functions. The :py:class:`Category` model in this package does this.
#. Create a model that subclasses :py:class:`CategoryBase` as above.
#. Add new fields to the model. The :py:class:`Category` model adds these extra fields.
.. literalinclude:: code_examples/custom_categories3.py
:linenos:
#. Add new methods to the model. For example, the :py:class:`Category` model adds several new methods, including overriding the :py:meth:`save` method.
.. literalinclude:: code_examples/custom_categories4.py
:linenos:
#. Alter :py:class:`Meta` or :py:class:`MPTTMeta` class. Either of these inner classes can be overridden, however your :py:class:`Meta` class should inherit :py:class:`CategoryBase.Meta`. Options for :py:class:`Meta` are in the `Django-MPTT docs <http://readthedocs.org/docs/django-mptt/en/latest/models.html#model-options>`_.
.. literalinclude:: code_examples/custom_categories5.py
:linenos:
#. For the admin, you must create a form that subclasses :py:class:`CategoryBaseAdminForm` and at least sets the ``Meta.model`` attribute. You can also alter the form fields and cleaning methods, as :py:class:`Category` does.
.. literalinclude:: code_examples/custom_categories6.py
:linenos:
#. Next you must subclass :py:class:`CategoryBaseAdmin` and assign the ``form`` attribute the form class created above. You can alter any other attributes as necessary.
.. literalinclude:: code_examples/custom_categories7.py
:linenos:

View file

@ -4,7 +4,7 @@ Getting Started
You can use Django Categories in two ways: You can use Django Categories in two ways:
1. As storage for one tree of categories, e.g.:: 1. As storage for one tree of categories, using the :py:class:`Category` model::
Top Category 1 Top Category 1
Subcategory 1-1 Subcategory 1-1
@ -13,24 +13,29 @@ You can use Django Categories in two ways:
Top Category 2 Top Category 2
Subcategory 2-1 Subcategory 2-1
2. As a storage of several trees of categories, e.g.:: 2. As the basis for several custom categories (see :ref:`creating_custom_categories`), e.g. a **MusicGenre** model
::
MusicGenre 1
MusicSubGenre 1-1
MusicSubGenre 1-2
MusicSubGenre 1-2-1
MusicGenre 2
MusicSubGenre 2-1
and a **Subject** model
::
Subject 1
Discipline 1-1
Discipline 1-2
SubDiscipline 1-2-1
Subject 2
Discipline 2-1
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
You can't do it as both at the same time, though.
Connecting your model with Django-Categories Connecting your model with Django-Categories
============================================ ============================================
@ -42,7 +47,7 @@ For 3rd-party apps or even your own apps that you don't wish to add Django-Categ
.. _hard_coded_connection: .. _hard_coded_connection:
Hard Coded Connection Hard Coded Connection
********************* ---------------------
Hard coded connections are done in the exact same way you handle any other foreign key or many-to-many relations to a model. Hard coded connections are done in the exact same way you handle any other foreign key or many-to-many relations to a model.
@ -60,10 +65,10 @@ Don't forget to add the field or fields to your ``ModelAdmin`` class as well.
.. _lazy_connection: .. _lazy_connection:
Lazy Connection Lazy Connection
*************** ---------------
Lazy connections are done through configuring Django Categories in the project's ``settings.py`` file. When the project starts up, the configured fields are dynamically added to the configured models and admin. Lazy connections are done through configuring Django Categories in the project's ``settings.py`` file. When the project starts up, the configured fields are dynamically added to the configured models and admin.
If you do this before you have created the database (before you ran ``manage.py syncdb``), the fields will also be in the tables. If you do this after you have already created all the tables, you can run ``manage.py add_category_fields`` to create the fields (this requires Django South to be installed). If you do this before you have created the database (before you ran ``manage.py syncdb``), the fields will also be in the tables. If you do this after you have already created all the tables, you can run ``manage.py add_category_fields`` to create the fields (this requires Django South to be installed).
You add a many-to-one or many-to-many relationship with Django Categories using the ``CATEGORIES_SETTINGS['FK_REGISTRY']`` and ``CATEGORIES_SETTINGS['M2M_REGISTRY']`` settings respectively. For more information see :ref:`registering_models`\ . You add a many-to-one or many-to-many relationship with Django Categories using the :ref:`FK_REGISTRY` and :ref:`M2M_REGISTRY` settings respectively. For more information see :ref:`registering_models`\ .

View file

@ -2,7 +2,35 @@
Django Categories v |version| Django Categories v |version|
============================= =============================
Contents: Django Categories grew out of our need to provide a basic hierarchical taxonomy management system that multiple applications could use independently or in concert.
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 1.0
==========
**Abstract Base Class for generic hierarchical category models**
When you want a multiple types of categories and don't want them all part of the same model, you can now easily create new models by subclassing ``CategoryBase``. You can also add additional metadata as necessary.
Your model's can subclass ``CategoryBaseAdminForm`` and ``CategoryBaseAdmin`` to get the hierarchical management in the admin.
See the docs for more information.
**Increased the default caching time on views**
The default setting for ``CACHE_VIEW_LENGTH`` was ``0``, which means it would tell the browser to *never* cache the page. It is now ``600``, which is the default for `CACHE_MIDDLEWARE_SECONDS <https://docs.djangoproject.com/en/1.3/ref/settings/#cache-middleware-seconds>`_
**Updated for use with Django-MPTT 0.5**
Just a few tweaks.
**Initial compatibility with Django 1.4**
More is coming, but at least it works.
**Slug transliteration for non-ASCII characters**
A new setting, ``SLUG_TRANSLITERATOR``, allows you to specify a function for converting the non-ASCII characters to ASCII characters before the slugification. Works great with `Unidecode <http://pypi.python.org/pypi/Unidecode>`_.
Contents
========
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
@ -13,6 +41,7 @@ Contents:
usage usage
registering_models registering_models
adding_the_fields adding_the_fields
custom_categories
reference/index reference/index
Indices and tables Indices and tables

View file

@ -2,11 +2,14 @@
Installation Installation
============ ============
To use the Category model
=========================
1. Install django-categories:: 1. Install django-categories::
pip install django-categories pip install django-categories
2. Add ``"categories"`` and ``"editor"`` to your ``INSTALLED_APPS`` list in your project's ``settings.py`` file. 2. Add ``"categories"`` and ``"categories.editor"`` to your ``INSTALLED_APPS`` list in your project's ``settings.py`` file.
.. code-block:: python .. code-block:: python
@ -17,3 +20,24 @@ Installation
] ]
3. Run ``./manage.py syncdb`` (or ``./manage.py migrate categories`` if you are using `South <http://south.aeracode.org/>`_) 3. Run ``./manage.py syncdb`` (or ``./manage.py migrate categories`` if you are using `South <http://south.aeracode.org/>`_)
To only subclass CategoryBase
=============================
If you are going to create your own models using :py:class:`CategoryBase`, (see :ref:`creating_custom_categories`) you'll need a few different steps.
1. Install django-categories::
pip install django-categories
2. Add ``"categories.editor"`` to your ``INSTALLED_APPS`` list in your project's ``settings.py`` file.
.. code-block:: python
INSTALLED_APPS = [
# ...
"categories.editor",
]
3. Create your own models.

View file

@ -2,41 +2,114 @@
Models Models
====== ======
CategoryBase
============
.. py:class:: CategoryBase
.. py:attribute:: parent
:py:class:`TreeForeignKey` ``(self)``
The category's parent category. Leave this blank for an root category.
.. py:attribute:: name
**Required** ``CharField(100)``
The name of the category.
.. py:attribute:: slug
**Required** ``SlugField``
URL-friendly title. It is automatically generated from the title.
.. py:attribute:: active
**Required** ``BooleanField`` *default:* ``True``
Is this item active. If it is inactive, all children are set to inactive as well.
.. py:attribute:: objects
``CategoryManager``
An object manager that adds an ``active`` method for only selecting items whose ``active`` attribute is ``True``.
.. py:attribute:: tree
``TreeManager``
A Django-MPTT `TreeManager <http://readthedocs.org/docs/django-mptt/en/latest/models.html#the-treemanager-custom-manager>`_ instance.
Category Category
======== ========
**parent** .. py:class:: Category
The category's parent category. Leave this blank for an Category Tree.
Category is a subclass of :py:class:`CategoryBase` and includes all its attributes.
.. py:attribute:: thumbnail
``FileField``
An optional thumbnail, that is uploaded to :ref:`thumbnail_upload_path` via :ref:`THUMBNAIL_STORAGE`.
.. note:: Why isn't this an ``ImageField``?
For ``ImageField``\ s, Django checks the file system for the existance of the files to handle the height and width. In many cases this can lead to problems and impact performance.
For these reasons, a ``FileField`` that manually manages the width and height was chosen.
**name** .. py:attribute:: thumbnail_width
The name of the category.
``IntegerField``
The thumbnail width. Automatically set on save if a thumbnail is uploaded.
.. py:attribute:: thumbnail_height
``IntegerField``
The thumbnail height. Automatically set on save if a thumbnail is uploaded.
**thumbnail** .. py:attribute:: order
An optional thumbnail, that is uploaded to ``CATEGORY_SETTINGS['THUMBNAIL_UPLOAD_PATH']`` via ``CATEGORY_SETTINGS['THUMBNAIL_STORAGE']``\ .
**Required** ``IntegerField`` *default:* 0
A manually-managed order of this category in the listing. Items with the same order are sorted alphabetically.
**thumbnail_width** .. py:attribute:: alternate_title
The thumbnail width.
``CharField(100)``
An alternative title to use on pages with this category.
.. py:attribute:: alternate_url
``CharField(200)``
An alternative URL to use instead of the one derived from the category hierarchy.
.. note:: Why isn't this a ``URLField``?
For ``URLField``\ s, Django checks that the URL includes ``http://`` and the site name. This makes it impossible to use relative URLs in that field.
**thumbnail_height** .. py:attribute:: description
The thumbnail height.
``TextField``
An optional longer description of the category. Very useful on category landing pages.
**order** .. py:attribute:: meta_keywords
The order of this category in the listing
``CharField(255)``
**slug**
A slug created from the name field Comma-separated keywords for search engines.
**alternate_title** .. py:attribute:: meta_extra
An alternative title to use on pages with this category.
``TextField``
**alternate_url**
An alternative URL to use instead of the one derived from the category hierarchy. (Advanced) Any additional HTML to be placed verbatim in the ``<head>`` of the page.
**description**
An optional longer description of the category.
**meta_keywords**
Comma-separated keywords for search engines.
**meta_extra**
(Advanced) Any additional HTML to be placed verbatim in the ``<head>``

View file

@ -6,6 +6,10 @@ Settings
The ``CATEGORIES_SETTINGS`` dictionary is where you can override the default settings. You don't have to include all the settings; only the ones which you want to override. The ``CATEGORIES_SETTINGS`` dictionary is where you can override the default settings. You don't have to include all the settings; only the ones which you want to override.
.. contents::
:local:
The default settings are: The default settings are:
.. code-block:: python .. code-block:: python
@ -20,7 +24,10 @@ The default settings are:
'THUMBNAIL_STORAGE': settings.DEFAULT_FILE_STORAGE, 'THUMBNAIL_STORAGE': settings.DEFAULT_FILE_STORAGE,
'SLUG_TRANSLITERATOR': lambda x: x, 'SLUG_TRANSLITERATOR': lambda x: x,
} }
.. _ALLOW_SLUG_CHANGE:
ALLOW_SLUG_CHANGE ALLOW_SLUG_CHANGE
================= =================
@ -28,6 +35,8 @@ ALLOW_SLUG_CHANGE
**Description:** Changing the slug for a category can have serious consequences if it is used as part of a URL. Setting this to ``True`` will allow users to change the slug of a category. **Description:** Changing the slug for a category can have serious consequences if it is used as part of a URL. Setting this to ``True`` will allow users to change the slug of a category.
.. _SLUG_TRANSLITERATOR:
SLUG_TRANSLITERATOR SLUG_TRANSLITERATOR
=================== ===================
@ -37,6 +46,9 @@ SLUG_TRANSLITERATOR
A great tool for this is `Unidecode <http://pypi.python.org/pypi/Unidecode>`_. Use it by setting ``SLUG_TRANSLITERATOR`` to ``'unidecode.unidecode``. A great tool for this is `Unidecode <http://pypi.python.org/pypi/Unidecode>`_. Use it by setting ``SLUG_TRANSLITERATOR`` to ``'unidecode.unidecode``.
.. _CACHE_VIEW_LENGTH:
CACHE_VIEW_LENGTH CACHE_VIEW_LENGTH
================= =================
@ -44,6 +56,8 @@ CACHE_VIEW_LENGTH
**Description:** This setting will be deprecated soon, but in the mean time, it allows you to specify the amount of time each view result is cached. **Description:** This setting will be deprecated soon, but in the mean time, it allows you to specify the amount of time each view result is cached.
.. _RELATION_MODELS:
RELATION_MODELS RELATION_MODELS
=============== ===============
@ -51,6 +65,8 @@ RELATION_MODELS
**Description:** Relation models is a set of models that a user can associate with this category. You specify models using ``'app_name.modelname'`` syntax. **Description:** Relation models is a set of models that a user can associate with this category. You specify models using ``'app_name.modelname'`` syntax.
.. _M2M_REGISTRY:
M2M_REGISTRY M2M_REGISTRY
============ ============
@ -58,6 +74,8 @@ M2M_REGISTRY
**Description:** A dictionary where the keys are in ``'app_name.model_name'`` syntax, and the values are a string, dict, or tuple of dicts. See :ref:`registering_models`\ . **Description:** A dictionary where the keys are in ``'app_name.model_name'`` syntax, and the values are a string, dict, or tuple of dicts. See :ref:`registering_models`\ .
.. _FK_REGISTRY:
FK_REGISTRY FK_REGISTRY
============ ============
@ -65,6 +83,8 @@ FK_REGISTRY
**Description:** A dictionary where the keys are in ``'app_name.model_name'`` syntax, and the values are a string, dict, or tuple of dicts. See :ref:`registering_models`\ . **Description:** A dictionary where the keys are in ``'app_name.model_name'`` syntax, and the values are a string, dict, or tuple of dicts. See :ref:`registering_models`\ .
.. _THUMBNAIL_UPLOAD_PATH:
THUMBNAIL_UPLOAD_PATH THUMBNAIL_UPLOAD_PATH
===================== =====================
@ -72,6 +92,8 @@ THUMBNAIL_UPLOAD_PATH
**Description:** Where thumbnails for the categories will be saved. **Description:** Where thumbnails for the categories will be saved.
.. _THUMBNAIL_STORAGE:
THUMBNAIL_STORAGE THUMBNAIL_STORAGE
================= =================
@ -79,6 +101,8 @@ THUMBNAIL_STORAGE
**Description:** How to store the thumbnails. Allows for external storage engines like S3. **Description:** How to store the thumbnails. Allows for external storage engines like S3.
.. _JAVASCRIPT_URL:
JAVASCRIPT_URL JAVASCRIPT_URL
============== ==============

View file

@ -0,0 +1,58 @@
.. _creating_custom_categories:
==========================
Creating Custom Categories
==========================
Django Categories isn't just for using a single category model. It allows you to create your own custom category-like models with as little or much customization as you need.
Name only
=========
For many cases, you want a simple user-managed lookup table. You can do this with just a little bit of code. The resulting model will include name, slug and active fields and a hierarchical admin.
#. Create a model that subclasses :py:class:`CategoryBase`
.. literalinclude:: code_examples/custom_categories1.py
:linenos:
#. For the Django admin, create a subclass of :py:class:`CategoryBaseAdminForm`. Create an internal class called :py:class:`Meta` and assign the attribute ``model`` to your model (see line 9 in the example).
.. literalinclude:: code_examples/custom_categories2.py
:linenos:
#. Create a subclass of CategoryBaseAdmin and assign ``form`` attribute the class created above (see line 12 in the above example).
#. Register your model and custom model admin class.
Name and other data
===================
Sometimes you need more functionality, such as extra metadata and custom functions. The :py:class:`Category` model in this package does this.
#. Create a model that subclasses :py:class:`CategoryBase` as above.
#. Add new fields to the model. The :py:class:`Category` model adds these extra fields.
.. literalinclude:: code_examples/custom_categories3.py
:linenos:
#. Add new methods to the model. For example, the :py:class:`Category` model adds several new methods, including overriding the :py:meth:`save` method.
.. literalinclude:: code_examples/custom_categories4.py
:linenos:
#. Alter :py:class:`Meta` or :py:class:`MPTTMeta` class. Either of these inner classes can be overridden, however your :py:class:`Meta` class should inherit :py:class:`CategoryBase.Meta`. Options for :py:class:`Meta` are in the `Django-MPTT docs <http://readthedocs.org/docs/django-mptt/en/latest/models.html#model-options>`_.
.. literalinclude:: code_examples/custom_categories5.py
:linenos:
#. For the admin, you must create a form that subclasses :py:class:`CategoryBaseAdminForm` and at least sets the ``Meta.model`` attribute. You can also alter the form fields and cleaning methods, as :py:class:`Category` does.
.. literalinclude:: code_examples/custom_categories6.py
:linenos:
#. Next you must subclass :py:class:`CategoryBaseAdmin` and assign the ``form`` attribute the form class created above. You can alter any other attributes as necessary.
.. literalinclude:: code_examples/custom_categories7.py
:linenos:

View file

@ -4,7 +4,7 @@ Getting Started
You can use Django Categories in two ways: You can use Django Categories in two ways:
1. As storage for one tree of categories, e.g.:: 1. As storage for one tree of categories, using the :py:class:`Category` model::
Top Category 1 Top Category 1
Subcategory 1-1 Subcategory 1-1
@ -13,24 +13,29 @@ You can use Django Categories in two ways:
Top Category 2 Top Category 2
Subcategory 2-1 Subcategory 2-1
2. As a storage of several trees of categories, e.g.:: 2. As the basis for several custom categories (see :ref:`creating_custom_categories`), e.g. a **MusicGenre** model
::
MusicGenre 1
MusicSubGenre 1-1
MusicSubGenre 1-2
MusicSubGenre 1-2-1
MusicGenre 2
MusicSubGenre 2-1
and a **Subject** model
::
Subject 1
Discipline 1-1
Discipline 1-2
SubDiscipline 1-2-1
Subject 2
Discipline 2-1
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
You can't do it as both at the same time, though.
Connecting your model with Django-Categories Connecting your model with Django-Categories
============================================ ============================================
@ -42,7 +47,7 @@ For 3rd-party apps or even your own apps that you don't wish to add Django-Categ
.. _hard_coded_connection: .. _hard_coded_connection:
Hard Coded Connection Hard Coded Connection
********************* ---------------------
Hard coded connections are done in the exact same way you handle any other foreign key or many-to-many relations to a model. Hard coded connections are done in the exact same way you handle any other foreign key or many-to-many relations to a model.
@ -60,10 +65,10 @@ Don't forget to add the field or fields to your ``ModelAdmin`` class as well.
.. _lazy_connection: .. _lazy_connection:
Lazy Connection Lazy Connection
*************** ---------------
Lazy connections are done through configuring Django Categories in the project's ``settings.py`` file. When the project starts up, the configured fields are dynamically added to the configured models and admin. Lazy connections are done through configuring Django Categories in the project's ``settings.py`` file. When the project starts up, the configured fields are dynamically added to the configured models and admin.
If you do this before you have created the database (before you ran ``manage.py syncdb``), the fields will also be in the tables. If you do this after you have already created all the tables, you can run ``manage.py add_category_fields`` to create the fields (this requires Django South to be installed). If you do this before you have created the database (before you ran ``manage.py syncdb``), the fields will also be in the tables. If you do this after you have already created all the tables, you can run ``manage.py add_category_fields`` to create the fields (this requires Django South to be installed).
You add a many-to-one or many-to-many relationship with Django Categories using the ``CATEGORIES_SETTINGS['FK_REGISTRY']`` and ``CATEGORIES_SETTINGS['M2M_REGISTRY']`` settings respectively. For more information see :ref:`registering_models`\ . You add a many-to-one or many-to-many relationship with Django Categories using the :ref:`FK_REGISTRY` and :ref:`M2M_REGISTRY` settings respectively. For more information see :ref:`registering_models`\ .

View file

@ -2,7 +2,35 @@
Django Categories v |version| Django Categories v |version|
============================= =============================
Contents: Django Categories grew out of our need to provide a basic hierarchical taxonomy management system that multiple applications could use independently or in concert.
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 1.0
==========
**Abstract Base Class for generic hierarchical category models**
When you want a multiple types of categories and don't want them all part of the same model, you can now easily create new models by subclassing ``CategoryBase``. You can also add additional metadata as necessary.
Your model's can subclass ``CategoryBaseAdminForm`` and ``CategoryBaseAdmin`` to get the hierarchical management in the admin.
See the docs for more information.
**Increased the default caching time on views**
The default setting for ``CACHE_VIEW_LENGTH`` was ``0``, which means it would tell the browser to *never* cache the page. It is now ``600``, which is the default for `CACHE_MIDDLEWARE_SECONDS <https://docs.djangoproject.com/en/1.3/ref/settings/#cache-middleware-seconds>`_
**Updated for use with Django-MPTT 0.5**
Just a few tweaks.
**Initial compatibility with Django 1.4**
More is coming, but at least it works.
**Slug transliteration for non-ASCII characters**
A new setting, ``SLUG_TRANSLITERATOR``, allows you to specify a function for converting the non-ASCII characters to ASCII characters before the slugification. Works great with `Unidecode <http://pypi.python.org/pypi/Unidecode>`_.
Contents
========
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
@ -13,6 +41,7 @@ Contents:
usage usage
registering_models registering_models
adding_the_fields adding_the_fields
custom_categories
reference/index reference/index
Indices and tables Indices and tables

View file

@ -2,11 +2,14 @@
Installation Installation
============ ============
To use the Category model
=========================
1. Install django-categories:: 1. Install django-categories::
pip install django-categories pip install django-categories
2. Add ``"categories"`` and ``"editor"`` to your ``INSTALLED_APPS`` list in your project's ``settings.py`` file. 2. Add ``"categories"`` and ``"categories.editor"`` to your ``INSTALLED_APPS`` list in your project's ``settings.py`` file.
.. code-block:: python .. code-block:: python
@ -17,3 +20,24 @@ Installation
] ]
3. Run ``./manage.py syncdb`` (or ``./manage.py migrate categories`` if you are using `South <http://south.aeracode.org/>`_) 3. Run ``./manage.py syncdb`` (or ``./manage.py migrate categories`` if you are using `South <http://south.aeracode.org/>`_)
To only subclass CategoryBase
=============================
If you are going to create your own models using :py:class:`CategoryBase`, (see :ref:`creating_custom_categories`) you'll need a few different steps.
1. Install django-categories::
pip install django-categories
2. Add ``"categories.editor"`` to your ``INSTALLED_APPS`` list in your project's ``settings.py`` file.
.. code-block:: python
INSTALLED_APPS = [
# ...
"categories.editor",
]
3. Create your own models.

View file

@ -2,41 +2,114 @@
Models Models
====== ======
CategoryBase
============
.. py:class:: CategoryBase
.. py:attribute:: parent
:py:class:`TreeForeignKey` ``(self)``
The category's parent category. Leave this blank for an root category.
.. py:attribute:: name
**Required** ``CharField(100)``
The name of the category.
.. py:attribute:: slug
**Required** ``SlugField``
URL-friendly title. It is automatically generated from the title.
.. py:attribute:: active
**Required** ``BooleanField`` *default:* ``True``
Is this item active. If it is inactive, all children are set to inactive as well.
.. py:attribute:: objects
``CategoryManager``
An object manager that adds an ``active`` method for only selecting items whose ``active`` attribute is ``True``.
.. py:attribute:: tree
``TreeManager``
A Django-MPTT `TreeManager <http://readthedocs.org/docs/django-mptt/en/latest/models.html#the-treemanager-custom-manager>`_ instance.
Category Category
======== ========
**parent** .. py:class:: Category
The category's parent category. Leave this blank for an Category Tree.
Category is a subclass of :py:class:`CategoryBase` and includes all its attributes.
.. py:attribute:: thumbnail
``FileField``
An optional thumbnail, that is uploaded to :ref:`thumbnail_upload_path` via :ref:`THUMBNAIL_STORAGE`.
.. note:: Why isn't this an ``ImageField``?
For ``ImageField``\ s, Django checks the file system for the existance of the files to handle the height and width. In many cases this can lead to problems and impact performance.
For these reasons, a ``FileField`` that manually manages the width and height was chosen.
**name** .. py:attribute:: thumbnail_width
The name of the category.
``IntegerField``
The thumbnail width. Automatically set on save if a thumbnail is uploaded.
.. py:attribute:: thumbnail_height
``IntegerField``
The thumbnail height. Automatically set on save if a thumbnail is uploaded.
**thumbnail** .. py:attribute:: order
An optional thumbnail, that is uploaded to ``CATEGORY_SETTINGS['THUMBNAIL_UPLOAD_PATH']`` via ``CATEGORY_SETTINGS['THUMBNAIL_STORAGE']``\ .
**Required** ``IntegerField`` *default:* 0
A manually-managed order of this category in the listing. Items with the same order are sorted alphabetically.
**thumbnail_width** .. py:attribute:: alternate_title
The thumbnail width.
``CharField(100)``
An alternative title to use on pages with this category.
.. py:attribute:: alternate_url
``CharField(200)``
An alternative URL to use instead of the one derived from the category hierarchy.
.. note:: Why isn't this a ``URLField``?
For ``URLField``\ s, Django checks that the URL includes ``http://`` and the site name. This makes it impossible to use relative URLs in that field.
**thumbnail_height** .. py:attribute:: description
The thumbnail height.
``TextField``
An optional longer description of the category. Very useful on category landing pages.
**order** .. py:attribute:: meta_keywords
The order of this category in the listing
``CharField(255)``
**slug**
A slug created from the name field Comma-separated keywords for search engines.
**alternate_title** .. py:attribute:: meta_extra
An alternative title to use on pages with this category.
``TextField``
**alternate_url**
An alternative URL to use instead of the one derived from the category hierarchy. (Advanced) Any additional HTML to be placed verbatim in the ``<head>`` of the page.
**description**
An optional longer description of the category.
**meta_keywords**
Comma-separated keywords for search engines.
**meta_extra**
(Advanced) Any additional HTML to be placed verbatim in the ``<head>``

View file

@ -6,6 +6,10 @@ Settings
The ``CATEGORIES_SETTINGS`` dictionary is where you can override the default settings. You don't have to include all the settings; only the ones which you want to override. The ``CATEGORIES_SETTINGS`` dictionary is where you can override the default settings. You don't have to include all the settings; only the ones which you want to override.
.. contents::
:local:
The default settings are: The default settings are:
.. code-block:: python .. code-block:: python
@ -18,8 +22,12 @@ The default settings are:
'FK_REGISTRY': {}, 'FK_REGISTRY': {},
'THUMBNAIL_UPLOAD_PATH': 'uploads/categories/thumbnails', 'THUMBNAIL_UPLOAD_PATH': 'uploads/categories/thumbnails',
'THUMBNAIL_STORAGE': settings.DEFAULT_FILE_STORAGE, 'THUMBNAIL_STORAGE': settings.DEFAULT_FILE_STORAGE,
'SLUG_TRANSLITERATOR': lambda x: x,
} }
.. _ALLOW_SLUG_CHANGE:
ALLOW_SLUG_CHANGE ALLOW_SLUG_CHANGE
================= =================
@ -27,6 +35,20 @@ ALLOW_SLUG_CHANGE
**Description:** Changing the slug for a category can have serious consequences if it is used as part of a URL. Setting this to ``True`` will allow users to change the slug of a category. **Description:** Changing the slug for a category can have serious consequences if it is used as part of a URL. Setting this to ``True`` will allow users to change the slug of a category.
.. _SLUG_TRANSLITERATOR:
SLUG_TRANSLITERATOR
===================
**Default:** ``lambda x: x``
**Description:** Allows the specification of a function to convert non-ASCII characters in the potential slug to ASCII characters. Allows specifying a ``callable()`` or a string in the form of ``'path.to.module.function'``.
A great tool for this is `Unidecode <http://pypi.python.org/pypi/Unidecode>`_. Use it by setting ``SLUG_TRANSLITERATOR`` to ``'unidecode.unidecode``.
.. _CACHE_VIEW_LENGTH:
CACHE_VIEW_LENGTH CACHE_VIEW_LENGTH
================= =================
@ -34,6 +56,8 @@ CACHE_VIEW_LENGTH
**Description:** This setting will be deprecated soon, but in the mean time, it allows you to specify the amount of time each view result is cached. **Description:** This setting will be deprecated soon, but in the mean time, it allows you to specify the amount of time each view result is cached.
.. _RELATION_MODELS:
RELATION_MODELS RELATION_MODELS
=============== ===============
@ -41,6 +65,8 @@ RELATION_MODELS
**Description:** Relation models is a set of models that a user can associate with this category. You specify models using ``'app_name.modelname'`` syntax. **Description:** Relation models is a set of models that a user can associate with this category. You specify models using ``'app_name.modelname'`` syntax.
.. _M2M_REGISTRY:
M2M_REGISTRY M2M_REGISTRY
============ ============
@ -48,6 +74,8 @@ M2M_REGISTRY
**Description:** A dictionary where the keys are in ``'app_name.model_name'`` syntax, and the values are a string, dict, or tuple of dicts. See :ref:`registering_models`\ . **Description:** A dictionary where the keys are in ``'app_name.model_name'`` syntax, and the values are a string, dict, or tuple of dicts. See :ref:`registering_models`\ .
.. _FK_REGISTRY:
FK_REGISTRY FK_REGISTRY
============ ============
@ -55,6 +83,8 @@ FK_REGISTRY
**Description:** A dictionary where the keys are in ``'app_name.model_name'`` syntax, and the values are a string, dict, or tuple of dicts. See :ref:`registering_models`\ . **Description:** A dictionary where the keys are in ``'app_name.model_name'`` syntax, and the values are a string, dict, or tuple of dicts. See :ref:`registering_models`\ .
.. _THUMBNAIL_UPLOAD_PATH:
THUMBNAIL_UPLOAD_PATH THUMBNAIL_UPLOAD_PATH
===================== =====================
@ -62,6 +92,8 @@ THUMBNAIL_UPLOAD_PATH
**Description:** Where thumbnails for the categories will be saved. **Description:** Where thumbnails for the categories will be saved.
.. _THUMBNAIL_STORAGE:
THUMBNAIL_STORAGE THUMBNAIL_STORAGE
================= =================
@ -69,6 +101,8 @@ THUMBNAIL_STORAGE
**Description:** How to store the thumbnails. Allows for external storage engines like S3. **Description:** How to store the thumbnails. Allows for external storage engines like S3.
.. _JAVASCRIPT_URL:
JAVASCRIPT_URL JAVASCRIPT_URL
============== ==============

View file

@ -4,7 +4,7 @@
* *
* Sphinx stylesheet -- basic theme. * Sphinx stylesheet -- basic theme.
* *
* :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details. * :license: BSD, see LICENSE for details.
* *
*/ */
@ -79,14 +79,6 @@ div.sphinxsidebar input {
font-size: 1em; font-size: 1em;
} }
div.sphinxsidebar input[type="text"] {
width: 170px;
}
div.sphinxsidebar input[type="submit"] {
width: 30px;
}
img { img {
border: 0; border: 0;
} }
@ -244,6 +236,7 @@ img.align-center, .figure.align-center, object.align-center {
} }
.align-center { .align-center {
clear: both;
text-align: center; text-align: center;
} }
@ -420,7 +413,7 @@ dl.glossary dt {
} }
.footnote:target { .footnote:target {
background-color: #ffa; background-color: #ffa
} }
.line-block { .line-block {
@ -447,16 +440,10 @@ dl.glossary dt {
font-style: oblique; font-style: oblique;
} }
abbr, acronym {
border-bottom: dotted 1px;
cursor: help;
}
/* -- code displays --------------------------------------------------------- */ /* -- code displays --------------------------------------------------------- */
pre { pre {
overflow: auto; overflow: auto;
overflow-y: hidden; /* fixes display issues on Chrome browsers */
} }
td.linenos pre { td.linenos pre {
@ -537,4 +524,4 @@ span.eqno {
#top-link { #top-link {
display: none; display: none;
} }
} }

View file

@ -532,6 +532,10 @@ pre {
padding: 10px; padding: 10px;
} }
td.linenos {
width: 2em;
}
td.linenos pre { td.linenos pre {
padding: 5px 0px; padding: 5px 0px;
border: 0; border: 0;
@ -539,14 +543,23 @@ td.linenos pre {
color: #aaa; color: #aaa;
} }
td.code {
}
table.highlighttable { table.highlighttable {
margin-left: 0.5em; margin-left: 0.5em;
width: 100%;
} }
table.highlighttable td { table.highlighttable td {
padding: 0 0.5em 0 0.5em; padding: 0 0.5em 0 0.5em;
} }
table.highlighttable td.linenos {
text-align: right;
width: 1.5em;
padding-right: 0;
}
tt { tt {
font-family:"Bitstream Vera Sans Mono",Monaco,"Lucida Console",Courier,Consolas,monospace; font-family:"Bitstream Vera Sans Mono",Monaco,"Lucida Console",Courier,Consolas,monospace;

View file

@ -2,9 +2,9 @@
* doctools.js * doctools.js
* ~~~~~~~~~~~ * ~~~~~~~~~~~
* *
* Sphinx JavaScript utilities for all documentation. * Sphinx JavaScript utilties for all documentation.
* *
* :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details. * :license: BSD, see LICENSE for details.
* *
*/ */
@ -185,9 +185,9 @@ var Documentation = {
body.highlightText(this.toLowerCase(), 'highlighted'); body.highlightText(this.toLowerCase(), 'highlighted');
}); });
}, 10); }, 10);
$('<p class="highlight-link"><a href="javascript:Documentation.' + $('<li class="highlight-link"><a href="javascript:Documentation.' +
'hideSearchWords()">' + _('Hide Search Matches') + '</a></p>') 'hideSearchWords()">' + _('Hide Search Matches') + '</a></li>')
.appendTo($('#searchbox')); .appendTo($('.sidebar .this-page-menu'));
} }
}, },
@ -213,7 +213,7 @@ var Documentation = {
* helper function to hide the search marks again * helper function to hide the search marks again
*/ */
hideSearchWords : function() { hideSearchWords : function() {
$('#searchbox .highlight-link').fadeOut(300); $('.sidebar .this-page-menu li.highlight-link').fadeOut(300);
$('span.highlighted').removeClass('highlighted'); $('span.highlighted').removeClass('highlighted');
}, },

View file

@ -1,10 +1,10 @@
/* /*
* searchtools.js_t * searchtools.js
* ~~~~~~~~~~~~~~~~ * ~~~~~~~~~~~~~~
* *
* Sphinx JavaScript utilties for the full-text search. * Sphinx JavaScript utilties for the full-text search.
* *
* :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details. * :license: BSD, see LICENSE for details.
* *
*/ */
@ -36,11 +36,10 @@ jQuery.makeSearchSummary = function(text, keywords, hlwords) {
return rv; return rv;
} }
/** /**
* Porter Stemmer * Porter Stemmer
*/ */
var Stemmer = function() { var PorterStemmer = function() {
var step2list = { var step2list = {
ational: 'ate', ational: 'ate',
@ -301,20 +300,20 @@ var Search = {
}, },
query : function(query) { query : function(query) {
var stopwords = ["and","then","into","it","as","are","in","if","for","no","there","their","was","is","be","to","that","but","they","not","such","with","by","a","on","these","of","will","this","near","the","or","at"]; var stopwords = ['and', 'then', 'into', 'it', 'as', 'are', 'in',
'if', 'for', 'no', 'there', 'their', 'was', 'is',
'be', 'to', 'that', 'but', 'they', 'not', 'such',
'with', 'by', 'a', 'on', 'these', 'of', 'will',
'this', 'near', 'the', 'or', 'at'];
// Stem the searchterms and add them to the correct list // stem the searchterms and add them to the correct list
var stemmer = new Stemmer(); var stemmer = new PorterStemmer();
var searchterms = []; var searchterms = [];
var excluded = []; var excluded = [];
var hlterms = []; var hlterms = [];
var tmp = query.split(/\s+/); var tmp = query.split(/\s+/);
var objectterms = []; var object = (tmp.length == 1) ? tmp[0].toLowerCase() : null;
for (var i = 0; i < tmp.length; i++) { for (var i = 0; i < tmp.length; i++) {
if (tmp[i] != "") {
objectterms.push(tmp[i].toLowerCase());
}
if ($u.indexOf(stopwords, tmp[i]) != -1 || tmp[i].match(/^\d+$/) || if ($u.indexOf(stopwords, tmp[i]) != -1 || tmp[i].match(/^\d+$/) ||
tmp[i] == "") { tmp[i] == "") {
// skip this "word" // skip this "word"
@ -345,6 +344,9 @@ var Search = {
var filenames = this._index.filenames; var filenames = this._index.filenames;
var titles = this._index.titles; var titles = this._index.titles;
var terms = this._index.terms; var terms = this._index.terms;
var objects = this._index.objects;
var objtypes = this._index.objtypes;
var objnames = this._index.objnames;
var fileMap = {}; var fileMap = {};
var files = null; var files = null;
// different result priorities // different result priorities
@ -355,19 +357,40 @@ var Search = {
$('#search-progress').empty(); $('#search-progress').empty();
// lookup as object // lookup as object
for (var i = 0; i < objectterms.length; i++) { if (object != null) {
var others = [].concat(objectterms.slice(0,i), for (var prefix in objects) {
objectterms.slice(i+1, objectterms.length)) for (var name in objects[prefix]) {
var results = this.performObjectSearch(objectterms[i], others); var fullname = (prefix ? prefix + '.' : '') + name;
// Assume first word is most likely to be the object, if (fullname.toLowerCase().indexOf(object) > -1) {
// other words more likely to be in description. match = objects[prefix][name];
// Therefore put matches for earlier words first. descr = objnames[match[1]] + _(', in ') + titles[match[0]];
// (Results are eventually used in reverse order). // XXX the generated anchors are not generally correct
objectResults = results[0].concat(objectResults); // XXX there may be custom prefixes
importantResults = results[1].concat(importantResults); result = [filenames[match[0]], fullname, '#'+fullname, descr];
unimportantResults = results[2].concat(unimportantResults); switch (match[2]) {
case 1: objectResults.push(result); break;
case 0: importantResults.push(result); break;
case 2: unimportantResults.push(result); break;
}
}
}
}
} }
// sort results descending
objectResults.sort(function(a, b) {
return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);
});
importantResults.sort(function(a, b) {
return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);
});
unimportantResults.sort(function(a, b) {
return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);
});
// perform the search on the required terms // perform the search on the required terms
for (var i = 0; i < searchterms.length; i++) { for (var i = 0; i < searchterms.length; i++) {
var word = searchterms[i]; var word = searchterms[i];
@ -466,7 +489,7 @@ var Search = {
listItem.slideDown(5, function() { listItem.slideDown(5, function() {
displayNextItem(); displayNextItem();
}); });
}, "text"); });
} else { } else {
// no source available, just display title // no source available, just display title
Search.output.append(listItem); Search.output.append(listItem);
@ -487,74 +510,9 @@ var Search = {
} }
} }
displayNextItem(); displayNextItem();
},
performObjectSearch : function(object, otherterms) {
var filenames = this._index.filenames;
var objects = this._index.objects;
var objnames = this._index.objnames;
var titles = this._index.titles;
var importantResults = [];
var objectResults = [];
var unimportantResults = [];
for (var prefix in objects) {
for (var name in objects[prefix]) {
var fullname = (prefix ? prefix + '.' : '') + name;
if (fullname.toLowerCase().indexOf(object) > -1) {
var match = objects[prefix][name];
var objname = objnames[match[1]][2];
var title = titles[match[0]];
// If more than one term searched for, we require other words to be
// found in the name/title/description
if (otherterms.length > 0) {
var haystack = (prefix + ' ' + name + ' ' +
objname + ' ' + title).toLowerCase();
var allfound = true;
for (var i = 0; i < otherterms.length; i++) {
if (haystack.indexOf(otherterms[i]) == -1) {
allfound = false;
break;
}
}
if (!allfound) {
continue;
}
}
var descr = objname + _(', in ') + title;
anchor = match[3];
if (anchor == '')
anchor = fullname;
else if (anchor == '-')
anchor = objnames[match[1]][1] + '-' + fullname;
result = [filenames[match[0]], fullname, '#'+anchor, descr];
switch (match[2]) {
case 1: objectResults.push(result); break;
case 0: importantResults.push(result); break;
case 2: unimportantResults.push(result); break;
}
}
}
}
// sort results descending
objectResults.sort(function(a, b) {
return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);
});
importantResults.sort(function(a, b) {
return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);
});
unimportantResults.sort(function(a, b) {
return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);
});
return [importantResults, objectResults, unimportantResults]
} }
} }
$(document).ready(function() { $(document).ready(function() {
Search.init(); Search.init();
}); });

View file

@ -16,7 +16,7 @@
* Once the browser is closed the cookie is deleted and the position * Once the browser is closed the cookie is deleted and the position
* reset to the default (expanded). * reset to the default (expanded).
* *
* :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details. * :license: BSD, see LICENSE for details.
* *
*/ */
@ -29,9 +29,6 @@ $(function() {
var sidebar = $('.sphinxsidebar'); var sidebar = $('.sphinxsidebar');
var sidebarwrapper = $('.sphinxsidebarwrapper'); var sidebarwrapper = $('.sphinxsidebarwrapper');
// for some reason, the document has no sidebar; do not run into errors
if (!sidebar.length) return;
// original margin-left of the bodywrapper and width of the sidebar // original margin-left of the bodywrapper and width of the sidebar
// with the sidebar expanded // with the sidebar expanded
var bw_margin_expanded = bodywrapper.css('margin-left'); var bw_margin_expanded = bodywrapper.css('margin-left');

View file

@ -1,10 +1,3 @@
// Underscore.js 0.5.5
// (c) 2009 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the terms of the MIT license.
// Portions of Underscore are inspired by or borrowed from Prototype.js,
// Oliver Steele's Functional, and John Resig's Micro-Templating.
// For all details and documentation:
// http://documentcloud.github.com/underscore/
(function(){var j=this,n=j._,i=function(a){this._wrapped=a},m=typeof StopIteration!=="undefined"?StopIteration:"__break__",b=j._=function(a){return new i(a)};if(typeof exports!=="undefined")exports._=b;var k=Array.prototype.slice,o=Array.prototype.unshift,p=Object.prototype.toString,q=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;b.VERSION="0.5.5";b.each=function(a,c,d){try{if(a.forEach)a.forEach(c,d);else if(b.isArray(a)||b.isArguments(a))for(var e=0,f=a.length;e<f;e++)c.call(d, (function(){var j=this,n=j._,i=function(a){this._wrapped=a},m=typeof StopIteration!=="undefined"?StopIteration:"__break__",b=j._=function(a){return new i(a)};if(typeof exports!=="undefined")exports._=b;var k=Array.prototype.slice,o=Array.prototype.unshift,p=Object.prototype.toString,q=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;b.VERSION="0.5.5";b.each=function(a,c,d){try{if(a.forEach)a.forEach(c,d);else if(b.isArray(a)||b.isArguments(a))for(var e=0,f=a.length;e<f;e++)c.call(d,
a[e],e,a);else{var g=b.keys(a);f=g.length;for(e=0;e<f;e++)c.call(d,a[g[e]],g[e],a)}}catch(h){if(h!=m)throw h;}return a};b.map=function(a,c,d){if(a&&b.isFunction(a.map))return a.map(c,d);var e=[];b.each(a,function(f,g,h){e.push(c.call(d,f,g,h))});return e};b.reduce=function(a,c,d,e){if(a&&b.isFunction(a.reduce))return a.reduce(b.bind(d,e),c);b.each(a,function(f,g,h){c=d.call(e,c,f,g,h)});return c};b.reduceRight=function(a,c,d,e){if(a&&b.isFunction(a.reduceRight))return a.reduceRight(b.bind(d,e),c); a[e],e,a);else{var g=b.keys(a);f=g.length;for(e=0;e<f;e++)c.call(d,a[g[e]],g[e],a)}}catch(h){if(h!=m)throw h;}return a};b.map=function(a,c,d){if(a&&b.isFunction(a.map))return a.map(c,d);var e=[];b.each(a,function(f,g,h){e.push(c.call(d,f,g,h))});return e};b.reduce=function(a,c,d,e){if(a&&b.isFunction(a.reduce))return a.reduce(b.bind(d,e),c);b.each(a,function(f,g,h){c=d.call(e,c,f,g,h)});return c};b.reduceRight=function(a,c,d,e){if(a&&b.isFunction(a.reduceRight))return a.reduceRight(b.bind(d,e),c);
var f=b.clone(b.toArray(a)).reverse();b.each(f,function(g,h){c=d.call(e,c,g,h,a)});return c};b.detect=function(a,c,d){var e;b.each(a,function(f,g,h){if(c.call(d,f,g,h)){e=f;b.breakLoop()}});return e};b.select=function(a,c,d){if(a&&b.isFunction(a.filter))return a.filter(c,d);var e=[];b.each(a,function(f,g,h){c.call(d,f,g,h)&&e.push(f)});return e};b.reject=function(a,c,d){var e=[];b.each(a,function(f,g,h){!c.call(d,f,g,h)&&e.push(f)});return e};b.all=function(a,c,d){c=c||b.identity;if(a&&b.isFunction(a.every))return a.every(c, var f=b.clone(b.toArray(a)).reverse();b.each(f,function(g,h){c=d.call(e,c,g,h,a)});return c};b.detect=function(a,c,d){var e;b.each(a,function(f,g,h){if(c.call(d,f,g,h)){e=f;b.breakLoop()}});return e};b.select=function(a,c,d){if(a&&b.isFunction(a.filter))return a.filter(c,d);var e=[];b.each(a,function(f,g,h){c.call(d,f,g,h)&&e.push(f)});return e};b.reject=function(a,c,d){var e=[];b.each(a,function(f,g,h){!c.call(d,f,g,h)&&e.push(f)});return e};b.all=function(a,c,d){c=c||b.identity;if(a&&b.isFunction(a.every))return a.every(c,

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Adding the fields to the database &mdash; Django Categories 0.8.8 documentation</title> <title>Adding the fields to the database &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '', URL_ROOT: '',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,13 +21,13 @@
<script type="text/javascript" src="_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="index.html" />
<link rel="next" title="Reference" href="reference/index.html" /> <link rel="next" title="Creating Custom Categories" href="custom_categories.html" />
<link rel="prev" title="Registering Models" href="registering_models.html" /> <link rel="prev" title="Registering Models" href="registering_models.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Adding the fields to the database</h1></div> <div id="title"><h1>Adding the fields to the database</h1></div>
@ -38,7 +35,7 @@
<li id="toc_button"><div class="headerButton"><a href="#">Table of Contents</a></div></li> <li id="toc_button"><div class="headerButton"><a href="#">Table of Contents</a></div></li>
<li id="page_buttons"> <li id="page_buttons">
<div class="headerButton"><a href="genindex.html" title="General Index" accesskey="I">index</a></div> <div class="headerButton"><a href="genindex.html" title="General Index" accesskey="I">index</a></div>
<div class="headerButton"><a href="reference/index.html" title="Reference" accesskey="N">next</a></div> <div class="headerButton"><a href="custom_categories.html" title="Creating Custom Categories" accesskey="N">next</a></div>
<div class="headerButton"><a href="registering_models.html" title="Registering Models" accesskey="P">previous</a></div> <div class="headerButton"><a href="registering_models.html" title="Registering Models" accesskey="P">previous</a></div>
</li> </li>
</ul> </ul>
@ -57,6 +54,7 @@
<li class="toctree-l2"><a class="reference internal" href="#reconfiguring-fields">Reconfiguring Fields</a></li> <li class="toctree-l2"><a class="reference internal" href="#reconfiguring-fields">Reconfiguring Fields</a></li>
</ul> </ul>
</li> </li>
<li class="toctree-l1"><a class="reference internal" href="custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
</ul> </ul>
@ -115,7 +113,7 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

351
docs/custom_categories.html Normal file
View file

@ -0,0 +1,351 @@
<!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>Creating Custom Categories &mdash; Django Categories v1.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: '1.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 Categories v1.0b1 documentation" href="index.html" />
<link rel="next" title="Reference" href="reference/index.html" />
<link rel="prev" title="Adding the fields to the database" href="adding_the_fields.html" />
</head>
<body>
<div id="docstitle">
<p>Django Categories v1.0b1 documentation</p>
</div>
<div id="header">
<div id="title"><h1>Creating Custom Categories</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="reference/index.html" title="Reference" accesskey="N">next</a></div>
<div class="headerButton"><a href="adding_the_fields.html" title="Adding the fields to the database" 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"><a class="reference internal" href="installation.html">Installation</a></li>
<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"><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 current"><a class="current reference internal" href="">Creating Custom Categories</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#name-only">Name only</a></li>
<li class="toctree-l2"><a class="reference internal" href="#name-and-other-data">Name and other data</a></li>
</ul>
</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/custom_categories.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">&nbsp;</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="creating-custom-categories">
<span id="id1"></span><h1>Creating Custom Categories<a class="headerlink" href="#creating-custom-categories" title="Permalink to this headline"></a></h1>
<p>Django Categories isn&#8217;t just for using a single category model. It allows you to create your own custom category-like models with as little or much customization as you need.</p>
<div class="section" id="name-only">
<h2>Name only<a class="headerlink" href="#name-only" title="Permalink to this headline"></a></h2>
<p>For many cases, you want a simple user-managed lookup table. You can do this with just a little bit of code. The resulting model will include name, slug and active fields and a hierarchical admin.</p>
<ol class="arabic">
<li><p class="first">Create a model that subclasses <a class="reference internal" href="reference/models.html#CategoryBase" title="CategoryBase"><tt class="xref py py-class docutils literal"><span class="pre">CategoryBase</span></tt></a></p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7
8
9</pre></div></td><td class="code"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">categories.models</span> <span class="kn">import</span> <span class="n">CategoryBase</span>
<span class="k">class</span> <span class="nc">SimpleCategory</span><span class="p">(</span><span class="n">CategoryBase</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A simple of catgorizing example</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="n">verbose_name_plural</span> <span class="o">=</span> <span class="s">&#39;simple categories&#39;</span>
</pre></div>
</td></tr></table></div>
</li>
<li><p class="first">For the Django admin, create a subclass of <tt class="xref py py-class docutils literal"><span class="pre">CategoryBaseAdminForm</span></tt>. Create an internal class called <tt class="xref py py-class docutils literal"><span class="pre">Meta</span></tt> and assign the attribute <tt class="docutils literal"><span class="pre">model</span></tt> to your model (see line 9 in the example).</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14</pre></div></td><td class="code"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">categories.admin</span> <span class="kn">import</span> <span class="n">CategoryBaseAdmin</span><span class="p">,</span> <span class="n">CategoryBaseAdminForm</span>
<span class="kn">from</span> <span class="nn">.models</span> <span class="kn">import</span> <span class="n">SimpleCategory</span>
<span class="k">class</span> <span class="nc">SimpleCategoryAdminForm</span><span class="p">(</span><span class="n">CategoryBaseAdminForm</span><span class="p">):</span>
<span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">SimpleCategory</span>
<span class="k">class</span> <span class="nc">SimpleCategoryAdmin</span><span class="p">(</span><span class="n">CategoryBaseAdmin</span><span class="p">):</span>
<span class="n">form</span> <span class="o">=</span> <span class="n">SimpleCategoryAdminForm</span>
<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">SimpleCategory</span><span class="p">,</span> <span class="n">SimpleCategoryAdmin</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</li>
<li><p class="first">Create a subclass of CategoryBaseAdmin and assign <tt class="docutils literal"><span class="pre">form</span></tt> attribute the class created above (see line 12 in the above example).</p>
</li>
<li><p class="first">Register your model and custom model admin class.</p>
</li>
</ol>
</div>
<div class="section" id="name-and-other-data">
<h2>Name and other data<a class="headerlink" href="#name-and-other-data" title="Permalink to this headline"></a></h2>
<p>Sometimes you need more functionality, such as extra metadata and custom functions. The <a class="reference internal" href="reference/models.html#Category" title="Category"><tt class="xref py py-class docutils literal"><span class="pre">Category</span></tt></a> model in this package does this.</p>
<ol class="arabic">
<li><p class="first">Create a model that subclasses <a class="reference internal" href="reference/models.html#CategoryBase" title="CategoryBase"><tt class="xref py py-class docutils literal"><span class="pre">CategoryBase</span></tt></a> as above.</p>
</li>
<li><p class="first">Add new fields to the model. The <a class="reference internal" href="reference/models.html#Category" title="Category"><tt class="xref py py-class docutils literal"><span class="pre">Category</span></tt></a> model adds these extra fields.</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 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</pre></div></td><td class="code"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Category</span><span class="p">(</span><span class="n">CategoryBase</span><span class="p">):</span>
<span class="n">thumbnail</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">FileField</span><span class="p">(</span>
<span class="n">upload_to</span><span class="o">=</span><span class="n">THUMBNAIL_UPLOAD_PATH</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">blank</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">storage</span><span class="o">=</span><span class="n">STORAGE</span><span class="p">(),)</span>
<span class="n">thumbnail_width</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">blank</span><span class="o">=</span><span class="bp">True</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">thumbnail_height</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">blank</span><span class="o">=</span><span class="bp">True</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">order</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">default</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">alternate_title</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">blank</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="s">&quot;&quot;</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">help_text</span><span class="o">=</span><span class="s">&quot;An alternative title to use on pages with this category.&quot;</span><span class="p">)</span>
<span class="n">alternate_url</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">blank</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">,</span>
<span class="n">help_text</span><span class="o">=</span><span class="s">&quot;An alternative URL to use instead of the one derived from &quot;</span>
<span class="s">&quot;the category hierarchy.&quot;</span><span class="p">)</span>
<span class="n">description</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">TextField</span><span class="p">(</span><span class="n">blank</span><span class="o">=</span><span class="bp">True</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">meta_keywords</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">blank</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="s">&quot;&quot;</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">help_text</span><span class="o">=</span><span class="s">&quot;Comma-separated keywords for search engines.&quot;</span><span class="p">)</span>
<span class="n">meta_extra</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">TextField</span><span class="p">(</span>
<span class="n">blank</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">,</span>
<span class="n">help_text</span><span class="o">=</span><span class="s">&quot;(Advanced) Any additional HTML to be placed verbatim &quot;</span>
<span class="s">&quot;in the &amp;lt;head&amp;gt;&quot;</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</li>
<li><p class="first">Add new methods to the model. For example, the <a class="reference internal" href="reference/models.html#Category" title="Category"><tt class="xref py py-class docutils literal"><span class="pre">Category</span></tt></a> model adds several new methods, including overriding the <tt class="xref py py-meth docutils literal"><span class="pre">save()</span></tt> method.</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15</pre></div></td><td class="code"><div class="highlight"><pre><span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">thumbnail</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">django.core.files.images</span> <span class="kn">import</span> <span class="n">get_image_dimensions</span>
<span class="kn">import</span> <span class="nn">django</span>
<span class="k">if</span> <span class="n">django</span><span class="o">.</span><span class="n">VERSION</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">width</span><span class="p">,</span> <span class="n">height</span> <span class="o">=</span> <span class="n">get_image_dimensions</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">thumbnail</span><span class="o">.</span><span class="n">file</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">width</span><span class="p">,</span> <span class="n">height</span> <span class="o">=</span> <span class="n">get_image_dimensions</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">thumbnail</span><span class="o">.</span><span class="n">file</span><span class="p">,</span> <span class="n">close</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">width</span><span class="p">,</span> <span class="n">height</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">thumbnail_width</span> <span class="o">=</span> <span class="n">width</span>
<span class="bp">self</span><span class="o">.</span><span class="n">thumbnail_height</span> <span class="o">=</span> <span class="n">height</span>
<span class="nb">super</span><span class="p">(</span><span class="n">Category</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</li>
<li><p class="first">Alter <tt class="xref py py-class docutils literal"><span class="pre">Meta</span></tt> or <tt class="xref py py-class docutils literal"><span class="pre">MPTTMeta</span></tt> class. Either of these inner classes can be overridden, however your <tt class="xref py py-class docutils literal"><span class="pre">Meta</span></tt> class should inherit <tt class="xref py py-class docutils literal"><span class="pre">CategoryBase.Meta</span></tt>. Options for <tt class="xref py py-class docutils literal"><span class="pre">Meta</span></tt> are in the <a class="reference external" href="http://readthedocs.org/docs/django-mptt/en/latest/models.html#model-options">Django-MPTT docs</a>.</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5</pre></div></td><td class="code"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Meta</span><span class="p">(</span><span class="n">CategoryBase</span><span class="o">.</span><span class="n">Meta</span><span class="p">):</span>
<span class="n">verbose_name_plural</span> <span class="o">=</span> <span class="s">&#39;categories&#39;</span>
<span class="k">class</span> <span class="nc">MPTTMeta</span><span class="p">:</span>
<span class="n">order_insertion_by</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;order&#39;</span><span class="p">,</span> <span class="s">&#39;name&#39;</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</li>
<li><p class="first">For the admin, you must create a form that subclasses <tt class="xref py py-class docutils literal"><span class="pre">CategoryBaseAdminForm</span></tt> and at least sets the <tt class="docutils literal"><span class="pre">Meta.model</span></tt> attribute. You can also alter the form fields and cleaning methods, as <a class="reference internal" href="reference/models.html#Category" title="Category"><tt class="xref py py-class docutils literal"><span class="pre">Category</span></tt></a> does.</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7
8
9</pre></div></td><td class="code"><div class="highlight"><pre><span class="k">class</span> <span class="nc">CategoryAdminForm</span><span class="p">(</span><span class="n">CategoryBaseAdminForm</span><span class="p">):</span>
<span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">Category</span>
<span class="k">def</span> <span class="nf">clean_alternate_title</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">instance</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s">&#39;alternate_title&#39;</span><span class="p">]:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s">&#39;alternate_title&#39;</span><span class="p">]</span>
</pre></div>
</td></tr></table></div>
</li>
<li><p class="first">Next you must subclass <tt class="xref py py-class docutils literal"><span class="pre">CategoryBaseAdmin</span></tt> and assign the <tt class="docutils literal"><span class="pre">form</span></tt> attribute the form class created above. You can alter any other attributes as necessary.</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17</pre></div></td><td class="code"><div class="highlight"><pre><span class="k">class</span> <span class="nc">CategoryAdmin</span><span class="p">(</span><span class="n">CategoryBaseAdmin</span><span class="p">):</span>
<span class="n">form</span> <span class="o">=</span> <span class="n">CategoryAdminForm</span>
<span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;alternate_title&#39;</span><span class="p">,</span> <span class="s">&#39;active&#39;</span><span class="p">)</span>
<span class="n">fieldsets</span> <span class="o">=</span> <span class="p">(</span>
<span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="p">{</span>
<span class="s">&#39;fields&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;parent&#39;</span><span class="p">,</span> <span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;thumbnail&#39;</span><span class="p">,</span> <span class="s">&#39;active&#39;</span><span class="p">)</span>
<span class="p">}),</span>
<span class="p">(</span><span class="s">&#39;Meta Data&#39;</span><span class="p">,</span> <span class="p">{</span>
<span class="s">&#39;fields&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;alternate_title&#39;</span><span class="p">,</span> <span class="s">&#39;alternate_url&#39;</span><span class="p">,</span> <span class="s">&#39;description&#39;</span><span class="p">,</span>
<span class="s">&#39;meta_keywords&#39;</span><span class="p">,</span> <span class="s">&#39;meta_extra&#39;</span><span class="p">),</span>
<span class="s">&#39;classes&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;collapse&#39;</span><span class="p">,),</span>
<span class="p">}),</span>
<span class="p">(</span><span class="s">&#39;Advanced&#39;</span><span class="p">,</span> <span class="p">{</span>
<span class="s">&#39;fields&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;order&#39;</span><span class="p">,</span> <span class="s">&#39;slug&#39;</span><span class="p">),</span>
<span class="s">&#39;classes&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;collapse&#39;</span><span class="p">,),</span>
<span class="p">}),</span>
<span class="p">)</span>
</pre></div>
</td></tr></table></div>
</li>
</ol>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
&copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p>
</div>
<div class="clearer"></div>
</div>
<div id="breadcrumbs">
Creating Custom Categories
</ul>
</div>
<script type="text/javascript" charset="utf-8" src="_static/toc.js"></script>
</body>
</html>

View file

@ -1,23 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Index &mdash; Django Categories 0.8.8 documentation</title> <title>Index &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '', URL_ROOT: '',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -26,11 +21,11 @@
<script type="text/javascript" src="_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="index.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Index</h1></div> <div id="title"><h1>Index</h1></div>
@ -51,6 +46,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="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="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="adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
</ul> </ul>
@ -85,26 +81,100 @@
<div class="body"> <div class="body">
<h1 id="index">Index</h1> <h1 id="index">Index</h1>
<div class="genindex-jumpbox">
<a href="#A"><strong>A</strong></a> | <a href="#C"><strong>C</strong></a> | <a href="#D"><strong>D</strong></a> | <a href="#M"><strong>M</strong></a> | <a href="#N"><strong>N</strong></a> | <a href="#O"><strong>O</strong></a> | <a href="#P"><strong>P</strong></a> | <a href="#R"><strong>R</strong></a> | <a href="#S"><strong>S</strong></a> | <a href="#T"><strong>T</strong></a>
</div>
<h2 id="A">A</h2>
<table width="100%" class="indextable genindextable"><tr>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#CategoryBase.active">active (CategoryBase attribute)</a></dt>
<dt><a href="reference/models.html#Category.alternate_title">alternate_title (Category attribute)</a></dt>
</dl></td>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#Category.alternate_url">alternate_url (Category attribute)</a></dt>
</dl></td>
</tr></table>
<h2 id="C">C</h2>
<table width="100%" class="indextable genindextable"><tr>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#Category">Category (built-in class)</a></dt>
</dl></td>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#CategoryBase">CategoryBase (built-in class)</a></dt>
</dl></td>
</tr></table>
<h2 id="D">D</h2>
<table width="100%" class="indextable genindextable"><tr>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#Category.description">description (Category attribute)</a></dt>
</dl></td>
</tr></table>
<h2 id="M">M</h2>
<table width="100%" class="indextable genindextable"><tr>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#Category.meta_extra">meta_extra (Category attribute)</a></dt>
</dl></td>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#Category.meta_keywords">meta_keywords (Category attribute)</a></dt>
</dl></td>
</tr></table>
<h2 id="N">N</h2>
<table width="100%" class="indextable genindextable"><tr>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#CategoryBase.name">name (CategoryBase attribute)</a></dt>
</dl></td>
</tr></table>
<h2 id="O">O</h2>
<table width="100%" class="indextable genindextable"><tr>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#CategoryBase.objects">objects (CategoryBase attribute)</a></dt>
</dl></td>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#Category.order">order (Category attribute)</a></dt>
</dl></td>
</tr></table>
<h2 id="P">P</h2>
<table width="100%" class="indextable genindextable"><tr>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#CategoryBase.parent">parent (CategoryBase attribute)</a></dt>
</dl></td>
</tr></table>
<div class="genindex-jumpbox">
<a href="#R"><strong>R</strong></a>
</div>
<h2 id="R">R</h2> <h2 id="R">R</h2>
<table style="width: 100%" class="indextable genindextable"><tr> <table width="100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl> <td width="33%" valign="top"><dl>
<dt><a href="registering_models.html#register_fk">register_fk() (built-in function)</a></dt>
<dt><a href="registering_models.html#register_fk">register_fk() (built-in function)</a> </dl></td>
</dt> <td width="33%" valign="top"><dl>
<dt><a href="registering_models.html#register_m2m">register_m2m() (built-in function)</a></dt>
</dl></td>
</tr></table>
</dl></td> <h2 id="S">S</h2>
<td style="width: 33%" valign="top"><dl> <table width="100%" class="indextable genindextable"><tr>
<td width="33%" valign="top"><dl>
<dt><a href="registering_models.html#register_m2m">register_m2m() (built-in function)</a> <dt><a href="reference/models.html#CategoryBase.slug">slug (CategoryBase attribute)</a></dt>
</dt> </dl></td>
</tr></table>
</dl></td> <h2 id="T">T</h2>
<table width="100%" class="indextable genindextable"><tr>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#Category.thumbnail">thumbnail (Category attribute)</a></dt>
<dt><a href="reference/models.html#Category.thumbnail_height">thumbnail_height (Category attribute)</a></dt>
</dl></td>
<td width="33%" valign="top"><dl>
<dt><a href="reference/models.html#Category.thumbnail_width">thumbnail_width (Category attribute)</a></dt>
<dt><a href="reference/models.html#CategoryBase.tree">tree (CategoryBase attribute)</a></dt>
</dl></td>
</tr></table> </tr></table>
@ -115,7 +185,7 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Getting Started &mdash; Django Categories 0.8.8 documentation</title> <title>Getting Started &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '', URL_ROOT: '',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,13 +21,13 @@
<script type="text/javascript" src="_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="index.html" />
<link rel="next" title="Using categories in templates" href="usage.html" /> <link rel="next" title="Using categories in templates" href="usage.html" />
<link rel="prev" title="Installation" href="installation.html" /> <link rel="prev" title="Installation" href="installation.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Getting Started</h1></div> <div id="title"><h1>Getting Started</h1></div>
@ -56,6 +53,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="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="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="adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
</ul> </ul>
@ -95,7 +93,7 @@
<h1>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline"></a></h1> <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> <p>You can use Django Categories in two ways:</p>
<ol class="arabic"> <ol class="arabic">
<li><p class="first">As storage for one tree of categories, e.g.:</p> <li><p class="first">As storage for one tree of categories, using the <a class="reference internal" href="reference/models.html#Category" title="Category"><tt class="xref py py-class docutils literal"><span class="pre">Category</span></tt></a> model:</p>
<div class="highlight-python"><pre>Top Category 1 <div class="highlight-python"><pre>Top Category 1
Subcategory 1-1 Subcategory 1-1
Subcategory 1-2 Subcategory 1-2
@ -104,25 +102,24 @@ Top Category 2
Subcategory 2-1</pre> Subcategory 2-1</pre>
</div> </div>
</li> </li>
<li><p class="first">As a storage of several trees of categories, e.g.:</p> <li><p class="first">As the basis for several custom categories (see <a class="reference internal" href="custom_categories.html#creating-custom-categories"><em>Creating Custom Categories</em></a>), e.g. a <strong>MusicGenre</strong> model</p>
<div class="highlight-python"><pre>Model 1 <div class="highlight-python"><pre>MusicGenre 1
Category 1 MusicSubGenre 1-1
Subcategory 1-1 MusicSubGenre 1-2
Subcategory 1-2 MusicSubGenre 1-2-1
subcategory 1-2-1 MusicGenre 2
Category 2 MusicSubGenre 2-1</pre>
Subcategory 2-1 </div>
Model 2 <p>and a <strong>Subject</strong> model</p>
Category 3 <div class="highlight-python"><pre>Subject 1
Subcategory 3-1 Discipline 1-1
Subcategory 3-2 Discipline 1-2
subcategory 3-2-1 SubDiscipline 1-2-1
Category 4 Subject 2
Subcategory 4-1</pre> Discipline 2-1</pre>
</div> </div>
</li> </li>
</ol> </ol>
<p>You can&#8217;t do it as both at the same time, though.</p>
<div class="section" id="connecting-your-model-with-django-categories"> <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> <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&#8217;s your application) or you are willing to take control of the code (fork someone else&#8217;s app) you can make a <a class="reference internal" href="#hard-coded-connection"><em>Hard Coded Connection</em></a>.</p> <p>There are two ways to add Category fields to an application. If you are in control of the code (it&#8217;s your application) or you are willing to take control of the code (fork someone else&#8217;s app) you can make a <a class="reference internal" href="#hard-coded-connection"><em>Hard Coded Connection</em></a>.</p>
@ -143,7 +140,7 @@ Model 2
<span id="id2"></span><h3>Lazy Connection<a class="headerlink" href="#lazy-connection" title="Permalink to this headline"></a></h3> <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&#8217;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>Lazy connections are done through configuring Django Categories in the project&#8217;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>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> <p>You add a many-to-one or many-to-many relationship with Django Categories using the <a class="reference internal" href="reference/settings.html#fk-registry"><em>FK_REGISTRY</em></a> and <a class="reference internal" href="reference/settings.html#m2m-registry"><em>M2M_REGISTRY</em></a> 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>
@ -155,7 +152,7 @@ Model 2
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Django Categories v 0.8 &mdash; Django Categories 0.8.8 documentation</title> <title>Django Categories v 1.0 &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '', URL_ROOT: '',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,15 +21,15 @@
<script type="text/javascript" src="_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="#" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="#" />
<link rel="next" title="Installation" href="installation.html" /> <link rel="next" title="Installation" href="installation.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Django Categories v 0.8</h1></div> <div id="title"><h1>Django Categories v 1.0</h1></div>
<ul id="headerButtons"> <ul id="headerButtons">
<li id="toc_button"><div class="headerButton"><a href="#">Table of Contents</a></div></li> <li id="toc_button"><div class="headerButton"><a href="#">Table of Contents</a></div></li>
<li id="page_buttons"> <li id="page_buttons">
@ -51,6 +48,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="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="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="adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
</ul> </ul>
@ -87,11 +85,36 @@
<div class="body"> <div class="body">
<div class="section" id="django-categories-v-version"> <div class="section" id="django-categories-v-version">
<h1>Django Categories v 0.8<a class="headerlink" href="#django-categories-v-version" title="Permalink to this headline"></a></h1> <h1>Django Categories v 1.0<a class="headerlink" href="#django-categories-v-version" title="Permalink to this headline"></a></h1>
<p>Contents:</p> <p>Django Categories grew out of our need to provide a basic hierarchical taxonomy management system that multiple applications could use independently or in concert.</p>
<p>As a news site, our stories, photos, and other content get divided into &#8220;sections&#8221; 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.</p>
<div class="section" id="new-in-1-0">
<h2>New in 1.0<a class="headerlink" href="#new-in-1-0" title="Permalink to this headline"></a></h2>
<dl class="docutils">
<dt><strong>Abstract Base Class for generic hierarchical category models</strong></dt>
<dd><p class="first">When you want a multiple types of categories and don&#8217;t want them all part of the same model, you can now easily create new models by subclassing <tt class="docutils literal"><span class="pre">CategoryBase</span></tt>. You can also add additional metadata as necessary.</p>
<p>Your model&#8217;s can subclass <tt class="docutils literal"><span class="pre">CategoryBaseAdminForm</span></tt> and <tt class="docutils literal"><span class="pre">CategoryBaseAdmin</span></tt> to get the hierarchical management in the admin.</p>
<p class="last">See the docs for more information.</p>
</dd>
<dt><strong>Increased the default caching time on views</strong></dt>
<dd>The default setting for <tt class="docutils literal"><span class="pre">CACHE_VIEW_LENGTH</span></tt> was <tt class="docutils literal"><span class="pre">0</span></tt>, which means it would tell the browser to <em>never</em> cache the page. It is now <tt class="docutils literal"><span class="pre">600</span></tt>, which is the default for <a class="reference external" href="https://docs.djangoproject.com/en/1.3/ref/settings/#cache-middleware-seconds">CACHE_MIDDLEWARE_SECONDS</a></dd>
<dt><strong>Updated for use with Django-MPTT 0.5</strong></dt>
<dd>Just a few tweaks.</dd>
<dt><strong>Initial compatibility with Django 1.4</strong></dt>
<dd>More is coming, but at least it works.</dd>
<dt><strong>Slug transliteration for non-ASCII characters</strong></dt>
<dd>A new setting, <tt class="docutils literal"><span class="pre">SLUG_TRANSLITERATOR</span></tt>, allows you to specify a function for converting the non-ASCII characters to ASCII characters before the slugification. Works great with <a class="reference external" href="http://pypi.python.org/pypi/Unidecode">Unidecode</a>.</dd>
</dl>
</div>
<div class="section" id="contents">
<h2>Contents<a class="headerlink" href="#contents" title="Permalink to this headline"></a></h2>
<div class="toctree-wrapper compound"> <div class="toctree-wrapper compound">
<ul> <ul>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li> <li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a><ul>
<li class="toctree-l2"><a class="reference internal" href="installation.html#to-use-the-category-model">To use the Category model</a></li>
<li class="toctree-l2"><a class="reference internal" href="installation.html#to-only-subclass-categorybase">To only subclass CategoryBase</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started</a><ul> <li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started</a><ul>
<li class="toctree-l2"><a class="reference internal" href="getting_started.html#connecting-your-model-with-django-categories">Connecting your model with Django-Categories</a></li> <li class="toctree-l2"><a class="reference internal" href="getting_started.html#connecting-your-model-with-django-categories">Connecting your model with Django-Categories</a></li>
</ul> </ul>
@ -112,6 +135,11 @@
<li class="toctree-l2"><a class="reference internal" href="adding_the_fields.html#reconfiguring-fields">Reconfiguring Fields</a></li> <li class="toctree-l2"><a class="reference internal" href="adding_the_fields.html#reconfiguring-fields">Reconfiguring Fields</a></li>
</ul> </ul>
</li> </li>
<li class="toctree-l1"><a class="reference internal" href="custom_categories.html">Creating Custom Categories</a><ul>
<li class="toctree-l2"><a class="reference internal" href="custom_categories.html#name-only">Name only</a></li>
<li class="toctree-l2"><a class="reference internal" href="custom_categories.html#name-and-other-data">Name and other data</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a><ul> <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/management_commands.html">Management Commands</a></li> <li class="toctree-l2"><a class="reference internal" href="reference/management_commands.html">Management Commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="reference/models.html">Models</a></li> <li class="toctree-l2"><a class="reference internal" href="reference/models.html">Models</a></li>
@ -121,6 +149,7 @@
</li> </li>
</ul> </ul>
</div> </div>
</div>
<div class="section" id="indices-and-tables"> <div class="section" id="indices-and-tables">
<h2>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline"></a></h2> <h2>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline"></a></h2>
<ul class="simple"> <ul class="simple">
@ -138,13 +167,13 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>
</div> </div>
<div id="breadcrumbs"> <div id="breadcrumbs">
Django Categories v 0.8 Django Categories v 1.0
</ul> </ul>
</div> </div>
<script type="text/javascript" charset="utf-8" src="_static/toc.js"></script> <script type="text/javascript" charset="utf-8" src="_static/toc.js"></script>

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Installation &mdash; Django Categories 0.8.8 documentation</title> <title>Installation &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '', URL_ROOT: '',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,13 +21,13 @@
<script type="text/javascript" src="_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="index.html" />
<link rel="next" title="Getting Started" href="getting_started.html" /> <link rel="next" title="Getting Started" href="getting_started.html" />
<link rel="prev" title="Django Categories v 0.8" href="index.html" /> <link rel="prev" title="Django Categories v 1.0" href="index.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Installation</h1></div> <div id="title"><h1>Installation</h1></div>
@ -39,7 +36,7 @@
<li id="page_buttons"> <li id="page_buttons">
<div class="headerButton"><a href="genindex.html" title="General Index" accesskey="I">index</a></div> <div class="headerButton"><a href="genindex.html" title="General Index" accesskey="I">index</a></div>
<div class="headerButton"><a href="getting_started.html" title="Getting Started" accesskey="N">next</a></div> <div class="headerButton"><a href="getting_started.html" title="Getting Started" accesskey="N">next</a></div>
<div class="headerButton"><a href="index.html" title="Django Categories v 0.8" accesskey="P">previous</a></div> <div class="headerButton"><a href="index.html" title="Django Categories v 1.0" accesskey="P">previous</a></div>
</li> </li>
</ul> </ul>
</div> </div>
@ -48,11 +45,16 @@
<div class="sphinxsidebarwrapper"> <div class="sphinxsidebarwrapper">
<ul><li class="toctree-l1"><a href="index.html">Main Page</a></li></ul> <ul><li class="toctree-l1"><a href="index.html">Main Page</a></li></ul>
<ul class="current"> <ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="">Installation</a></li> <li class="toctree-l1 current"><a class="current reference internal" href="">Installation</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#to-use-the-category-model">To use the Category model</a></li>
<li class="toctree-l2"><a class="reference internal" href="#to-only-subclass-categorybase">To only subclass CategoryBase</a></li>
</ul>
</li>
<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="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"><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="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="adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
</ul> </ul>
@ -90,12 +92,14 @@
<div class="section" id="installation"> <div class="section" id="installation">
<h1>Installation<a class="headerlink" href="#installation" title="Permalink to this headline"></a></h1> <h1>Installation<a class="headerlink" href="#installation" title="Permalink to this headline"></a></h1>
<div class="section" id="to-use-the-category-model">
<h2>To use the Category model<a class="headerlink" href="#to-use-the-category-model" title="Permalink to this headline"></a></h2>
<ol class="arabic"> <ol class="arabic">
<li><p class="first">Install django-categories:</p> <li><p class="first">Install django-categories:</p>
<div class="highlight-python"><pre>pip install django-categories</pre> <div class="highlight-python"><pre>pip install django-categories</pre>
</div> </div>
</li> </li>
<li><p class="first">Add <tt class="docutils literal"><span class="pre">&quot;categories&quot;</span></tt> and <tt class="docutils literal"><span class="pre">&quot;editor&quot;</span></tt> to your <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt> list in your project&#8217;s <tt class="docutils literal"><span class="pre">settings.py</span></tt> file.</p> <li><p class="first">Add <tt class="docutils literal"><span class="pre">&quot;categories&quot;</span></tt> and <tt class="docutils literal"><span class="pre">&quot;categories.editor&quot;</span></tt> to your <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt> list in your project&#8217;s <tt class="docutils literal"><span class="pre">settings.py</span></tt> file.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">INSTALLED_APPS</span> <span class="o">=</span> <span class="p">[</span> <div class="highlight-python"><div class="highlight"><pre><span class="n">INSTALLED_APPS</span> <span class="o">=</span> <span class="p">[</span>
<span class="c"># ...</span> <span class="c"># ...</span>
<span class="s">&quot;categories&quot;</span><span class="p">,</span> <span class="s">&quot;categories&quot;</span><span class="p">,</span>
@ -107,6 +111,27 @@
<li><p class="first">Run <tt class="docutils literal"><span class="pre">./manage.py</span> <span class="pre">syncdb</span></tt> (or <tt class="docutils literal"><span class="pre">./manage.py</span> <span class="pre">migrate</span> <span class="pre">categories</span></tt> if you are using <a class="reference external" href="http://south.aeracode.org/">South</a>)</p> <li><p class="first">Run <tt class="docutils literal"><span class="pre">./manage.py</span> <span class="pre">syncdb</span></tt> (or <tt class="docutils literal"><span class="pre">./manage.py</span> <span class="pre">migrate</span> <span class="pre">categories</span></tt> if you are using <a class="reference external" href="http://south.aeracode.org/">South</a>)</p>
</li> </li>
</ol> </ol>
</div>
<div class="section" id="to-only-subclass-categorybase">
<h2>To only subclass CategoryBase<a class="headerlink" href="#to-only-subclass-categorybase" title="Permalink to this headline"></a></h2>
<p>If you are going to create your own models using <a class="reference internal" href="reference/models.html#CategoryBase" title="CategoryBase"><tt class="xref py py-class docutils literal"><span class="pre">CategoryBase</span></tt></a>, (see <a class="reference internal" href="custom_categories.html#creating-custom-categories"><em>Creating Custom Categories</em></a>) you&#8217;ll need a few different steps.</p>
<ol class="arabic">
<li><p class="first">Install django-categories:</p>
<div class="highlight-python"><pre>pip install django-categories</pre>
</div>
</li>
<li><p class="first">Add <tt class="docutils literal"><span class="pre">&quot;categories.editor&quot;</span></tt> to your <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt> list in your project&#8217;s <tt class="docutils literal"><span class="pre">settings.py</span></tt> file.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">INSTALLED_APPS</span> <span class="o">=</span> <span class="p">[</span>
<span class="c"># ...</span>
<span class="s">&quot;categories.editor&quot;</span><span class="p">,</span>
<span class="p">]</span>
</pre></div>
</div>
</li>
<li><p class="first">Create your own models.</p>
</li>
</ol>
</div>
</div> </div>
@ -116,7 +141,7 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

Binary file not shown.

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reference &mdash; Django Categories 0.8.8 documentation</title> <title>Reference &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../', URL_ROOT: '../',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,13 +21,13 @@
<script type="text/javascript" src="../_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="../index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="../index.html" />
<link rel="next" title="Management Commands" href="management_commands.html" /> <link rel="next" title="Management Commands" href="management_commands.html" />
<link rel="prev" title="Adding the fields to the database" href="../adding_the_fields.html" /> <link rel="prev" title="Creating Custom Categories" href="../custom_categories.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Reference</h1></div> <div id="title"><h1>Reference</h1></div>
@ -39,7 +36,7 @@
<li id="page_buttons"> <li id="page_buttons">
<div class="headerButton"><a href="../genindex.html" title="General Index" accesskey="I">index</a></div> <div class="headerButton"><a href="../genindex.html" title="General Index" accesskey="I">index</a></div>
<div class="headerButton"><a href="management_commands.html" title="Management Commands" accesskey="N">next</a></div> <div class="headerButton"><a href="management_commands.html" title="Management Commands" accesskey="N">next</a></div>
<div class="headerButton"><a href="../adding_the_fields.html" title="Adding the fields to the database" accesskey="P">previous</a></div> <div class="headerButton"><a href="../custom_categories.html" title="Creating Custom Categories" accesskey="P">previous</a></div>
</li> </li>
</ul> </ul>
</div> </div>
@ -53,6 +50,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="../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="../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="../adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="../custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Reference</a><ul> <li class="toctree-l1 current"><a class="current reference internal" href="">Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="management_commands.html">Management Commands</a></li> <li class="toctree-l2"><a class="reference internal" href="management_commands.html">Management Commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li> <li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li>
@ -105,11 +103,13 @@
</ul> </ul>
</li> </li>
<li class="toctree-l1"><a class="reference internal" href="models.html">Models</a><ul> <li class="toctree-l1"><a class="reference internal" href="models.html">Models</a><ul>
<li class="toctree-l2"><a class="reference internal" href="models.html#categorybase">CategoryBase</a></li>
<li class="toctree-l2"><a class="reference internal" href="models.html#category">Category</a></li> <li class="toctree-l2"><a class="reference internal" href="models.html#category">Category</a></li>
</ul> </ul>
</li> </li>
<li class="toctree-l1"><a class="reference internal" href="settings.html">Settings</a><ul> <li class="toctree-l1"><a class="reference internal" href="settings.html">Settings</a><ul>
<li class="toctree-l2"><a class="reference internal" href="settings.html#allow-slug-change">ALLOW_SLUG_CHANGE</a></li> <li class="toctree-l2"><a class="reference internal" href="settings.html#allow-slug-change">ALLOW_SLUG_CHANGE</a></li>
<li class="toctree-l2"><a class="reference internal" href="settings.html#slug-transliterator">SLUG_TRANSLITERATOR</a></li>
<li class="toctree-l2"><a class="reference internal" href="settings.html#cache-view-length">CACHE_VIEW_LENGTH</a></li> <li class="toctree-l2"><a class="reference internal" href="settings.html#cache-view-length">CACHE_VIEW_LENGTH</a></li>
<li class="toctree-l2"><a class="reference internal" href="settings.html#relation-models">RELATION_MODELS</a></li> <li class="toctree-l2"><a class="reference internal" href="settings.html#relation-models">RELATION_MODELS</a></li>
<li class="toctree-l2"><a class="reference internal" href="settings.html#m2m-registry">M2M_REGISTRY</a></li> <li class="toctree-l2"><a class="reference internal" href="settings.html#m2m-registry">M2M_REGISTRY</a></li>
@ -138,7 +138,7 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Management Commands &mdash; Django Categories 0.8.8 documentation</title> <title>Management Commands &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../', URL_ROOT: '../',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,14 +21,14 @@
<script type="text/javascript" src="../_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="../index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="../index.html" />
<link rel="up" title="Reference" href="index.html" /> <link rel="up" title="Reference" href="index.html" />
<link rel="next" title="Models" href="models.html" /> <link rel="next" title="Models" href="models.html" />
<link rel="prev" title="Reference" href="index.html" /> <link rel="prev" title="Reference" href="index.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Management Commands</h1></div> <div id="title"><h1>Management Commands</h1></div>
@ -54,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="../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="../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="../adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="../custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Reference</a><ul class="current"> <li class="toctree-l1 current"><a class="reference internal" href="index.html">Reference</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="">Management Commands</a></li> <li class="toctree-l2 current"><a class="current reference internal" href="">Management Commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li> <li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li>
@ -123,7 +121,7 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Models &mdash; Django Categories 0.8.8 documentation</title> <title>Models &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../', URL_ROOT: '../',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,14 +21,14 @@
<script type="text/javascript" src="../_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="../index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="../index.html" />
<link rel="up" title="Reference" href="index.html" /> <link rel="up" title="Reference" href="index.html" />
<link rel="next" title="Settings" href="settings.html" /> <link rel="next" title="Settings" href="settings.html" />
<link rel="prev" title="Management Commands" href="management_commands.html" /> <link rel="prev" title="Management Commands" href="management_commands.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Models</h1></div> <div id="title"><h1>Models</h1></div>
@ -54,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="../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="../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="../adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="../custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Reference</a><ul class="current"> <li class="toctree-l1 current"><a class="reference internal" href="index.html">Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="management_commands.html">Management Commands</a></li> <li class="toctree-l2"><a class="reference internal" href="management_commands.html">Management Commands</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="">Models</a></li> <li class="toctree-l2 current"><a class="current reference internal" href="">Models</a></li>
@ -97,34 +95,138 @@
<div class="section" id="models"> <div class="section" id="models">
<h1>Models<a class="headerlink" href="#models" title="Permalink to this headline"></a></h1> <h1>Models<a class="headerlink" href="#models" title="Permalink to this headline"></a></h1>
<div class="section" id="categorybase">
<h2>CategoryBase<a class="headerlink" href="#categorybase" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="CategoryBase">
<em class="property">class </em><tt class="descname">CategoryBase</tt><a class="headerlink" href="#CategoryBase" title="Permalink to this definition"></a></dt>
<dd><dl class="attribute">
<dt id="CategoryBase.parent">
<tt class="descname">parent</tt><a class="headerlink" href="#CategoryBase.parent" title="Permalink to this definition"></a></dt>
<dd><p><tt class="xref py py-class docutils literal"><span class="pre">TreeForeignKey</span></tt> <tt class="docutils literal"><span class="pre">(self)</span></tt></p>
<p>The category&#8217;s parent category. Leave this blank for an root category.</p>
</dd></dl>
<dl class="attribute">
<dt id="CategoryBase.name">
<tt class="descname">name</tt><a class="headerlink" href="#CategoryBase.name" title="Permalink to this definition"></a></dt>
<dd><p><strong>Required</strong> <tt class="docutils literal"><span class="pre">CharField(100)</span></tt></p>
<p>The name of the category.</p>
</dd></dl>
<dl class="attribute">
<dt id="CategoryBase.slug">
<tt class="descname">slug</tt><a class="headerlink" href="#CategoryBase.slug" title="Permalink to this definition"></a></dt>
<dd><p><strong>Required</strong> <tt class="docutils literal"><span class="pre">SlugField</span></tt></p>
<p>URL-friendly title. It is automatically generated from the title.</p>
</dd></dl>
<dl class="attribute">
<dt id="CategoryBase.active">
<tt class="descname">active</tt><a class="headerlink" href="#CategoryBase.active" title="Permalink to this definition"></a></dt>
<dd><p><strong>Required</strong> <tt class="docutils literal"><span class="pre">BooleanField</span></tt> <em>default:</em> <tt class="xref docutils literal"><span class="pre">True</span></tt></p>
<p>Is this item active. If it is inactive, all children are set to inactive as well.</p>
</dd></dl>
<dl class="attribute">
<dt id="CategoryBase.objects">
<tt class="descname">objects</tt><a class="headerlink" href="#CategoryBase.objects" title="Permalink to this definition"></a></dt>
<dd><p><tt class="docutils literal"><span class="pre">CategoryManager</span></tt></p>
<p>An object manager that adds an <tt class="docutils literal"><span class="pre">active</span></tt> method for only selecting items whose <tt class="docutils literal"><span class="pre">active</span></tt> attribute is <tt class="xref docutils literal"><span class="pre">True</span></tt>.</p>
</dd></dl>
<dl class="attribute">
<dt id="CategoryBase.tree">
<tt class="descname">tree</tt><a class="headerlink" href="#CategoryBase.tree" title="Permalink to this definition"></a></dt>
<dd><p><tt class="docutils literal"><span class="pre">TreeManager</span></tt></p>
<p>A Django-MPTT <a class="reference external" href="http://readthedocs.org/docs/django-mptt/en/latest/models.html#the-treemanager-custom-manager">TreeManager</a> instance.</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="category"> <div class="section" id="category">
<h2>Category<a class="headerlink" href="#category" title="Permalink to this headline"></a></h2> <h2>Category<a class="headerlink" href="#category" title="Permalink to this headline"></a></h2>
<dl class="docutils"> <dl class="class">
<dt><strong>parent</strong></dt> <dt id="Category">
<dd>The category&#8217;s parent category. Leave this blank for an Category Tree.</dd> <em class="property">class </em><tt class="descname">Category</tt><a class="headerlink" href="#Category" title="Permalink to this definition"></a></dt>
<dt><strong>name</strong></dt> <dd><p>Category is a subclass of <a class="reference internal" href="#CategoryBase" title="CategoryBase"><tt class="xref py py-class docutils literal"><span class="pre">CategoryBase</span></tt></a> and includes all its attributes.</p>
<dd>The name of the category.</dd> <dl class="attribute">
<dt><strong>thumbnail</strong></dt> <dt id="Category.thumbnail">
<dd>An optional thumbnail, that is uploaded to <tt class="docutils literal"><span class="pre">CATEGORY_SETTINGS['THUMBNAIL_UPLOAD_PATH']</span></tt> via <tt class="docutils literal"><span class="pre">CATEGORY_SETTINGS['THUMBNAIL_STORAGE']</span></tt>.</dd> <tt class="descname">thumbnail</tt><a class="headerlink" href="#Category.thumbnail" title="Permalink to this definition"></a></dt>
<dt><strong>thumbnail_width</strong></dt> <dd><p><tt class="docutils literal"><span class="pre">FileField</span></tt></p>
<dd>The thumbnail width.</dd> <p>An optional thumbnail, that is uploaded to <a class="reference internal" href="settings.html#thumbnail-upload-path"><em>THUMBNAIL_UPLOAD_PATH</em></a> via <a class="reference internal" href="settings.html#thumbnail-storage"><em>THUMBNAIL_STORAGE</em></a>.</p>
<dt><strong>thumbnail_height</strong></dt> <div class="admonition note">
<dd>The thumbnail height.</dd> <p class="first admonition-title">Note</p>
<dt><strong>order</strong></dt> <p>Why isn&#8217;t this an <tt class="docutils literal"><span class="pre">ImageField</span></tt>?</p>
<dd>The order of this category in the listing</dd> <p>For <tt class="docutils literal"><span class="pre">ImageField</span></tt>s, Django checks the file system for the existance of the files to handle the height and width. In many cases this can lead to problems and impact performance.</p>
<dt><strong>slug</strong></dt> <p class="last">For these reasons, a <tt class="docutils literal"><span class="pre">FileField</span></tt> that manually manages the width and height was chosen.</p>
<dd>A slug created from the name field</dd> </div>
<dt><strong>alternate_title</strong></dt> </dd></dl>
<dd>An alternative title to use on pages with this category.</dd>
<dt><strong>alternate_url</strong></dt> <dl class="attribute">
<dd>An alternative URL to use instead of the one derived from the category hierarchy.</dd> <dt id="Category.thumbnail_width">
<dt><strong>description</strong></dt> <tt class="descname">thumbnail_width</tt><a class="headerlink" href="#Category.thumbnail_width" title="Permalink to this definition"></a></dt>
<dd>An optional longer description of the category.</dd> <dd><p><tt class="docutils literal"><span class="pre">IntegerField</span></tt></p>
<dt><strong>meta_keywords</strong></dt> <p>The thumbnail width. Automatically set on save if a thumbnail is uploaded.</p>
<dd>Comma-separated keywords for search engines.</dd> </dd></dl>
<dt><strong>meta_extra</strong></dt>
<dd>(Advanced) Any additional HTML to be placed verbatim in the <tt class="docutils literal"><span class="pre">&lt;head&gt;</span></tt></dd> <dl class="attribute">
</dl> <dt id="Category.thumbnail_height">
<tt class="descname">thumbnail_height</tt><a class="headerlink" href="#Category.thumbnail_height" title="Permalink to this definition"></a></dt>
<dd><p><tt class="docutils literal"><span class="pre">IntegerField</span></tt></p>
<p>The thumbnail height. Automatically set on save if a thumbnail is uploaded.</p>
</dd></dl>
<dl class="attribute">
<dt id="Category.order">
<tt class="descname">order</tt><a class="headerlink" href="#Category.order" title="Permalink to this definition"></a></dt>
<dd><p><strong>Required</strong> <tt class="docutils literal"><span class="pre">IntegerField</span></tt> <em>default:</em> 0</p>
<p>A manually-managed order of this category in the listing. Items with the same order are sorted alphabetically.</p>
</dd></dl>
<dl class="attribute">
<dt id="Category.alternate_title">
<tt class="descname">alternate_title</tt><a class="headerlink" href="#Category.alternate_title" title="Permalink to this definition"></a></dt>
<dd><p><tt class="docutils literal"><span class="pre">CharField(100)</span></tt></p>
<p>An alternative title to use on pages with this category.</p>
</dd></dl>
<dl class="attribute">
<dt id="Category.alternate_url">
<tt class="descname">alternate_url</tt><a class="headerlink" href="#Category.alternate_url" title="Permalink to this definition"></a></dt>
<dd><p><tt class="docutils literal"><span class="pre">CharField(200)</span></tt></p>
<p>An alternative URL to use instead of the one derived from the category hierarchy.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Why isn&#8217;t this a <tt class="docutils literal"><span class="pre">URLField</span></tt>?</p>
<p class="last">For <tt class="docutils literal"><span class="pre">URLField</span></tt>s, Django checks that the URL includes <tt class="docutils literal"><span class="pre">http://</span></tt> and the site name. This makes it impossible to use relative URLs in that field.</p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="Category.description">
<tt class="descname">description</tt><a class="headerlink" href="#Category.description" title="Permalink to this definition"></a></dt>
<dd><p><tt class="docutils literal"><span class="pre">TextField</span></tt></p>
<p>An optional longer description of the category. Very useful on category landing pages.</p>
</dd></dl>
<dl class="attribute">
<dt id="Category.meta_keywords">
<tt class="descname">meta_keywords</tt><a class="headerlink" href="#Category.meta_keywords" title="Permalink to this definition"></a></dt>
<dd><p><tt class="docutils literal"><span class="pre">CharField(255)</span></tt></p>
<p>Comma-separated keywords for search engines.</p>
</dd></dl>
<dl class="attribute">
<dt id="Category.meta_extra">
<tt class="descname">meta_extra</tt><a class="headerlink" href="#Category.meta_extra" title="Permalink to this definition"></a></dt>
<dd><p><tt class="docutils literal"><span class="pre">TextField</span></tt></p>
<p>(Advanced) Any additional HTML to be placed verbatim in the <tt class="docutils literal"><span class="pre">&lt;head&gt;</span></tt> of the page.</p>
</dd></dl>
</dd></dl>
</div> </div>
</div> </div>
@ -135,7 +237,7 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Settings &mdash; Django Categories 0.8.8 documentation</title> <title>Settings &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../', URL_ROOT: '../',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,14 +21,14 @@
<script type="text/javascript" src="../_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="../index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="../index.html" />
<link rel="up" title="Reference" href="index.html" /> <link rel="up" title="Reference" href="index.html" />
<link rel="next" title="Template Tags" href="templatetags.html" /> <link rel="next" title="Template Tags" href="templatetags.html" />
<link rel="prev" title="Models" href="models.html" /> <link rel="prev" title="Models" href="models.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Settings</h1></div> <div id="title"><h1>Settings</h1></div>
@ -54,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="../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="../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="../adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="../custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Reference</a><ul class="current"> <li class="toctree-l1 current"><a class="reference internal" href="index.html">Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="management_commands.html">Management Commands</a></li> <li class="toctree-l2"><a class="reference internal" href="management_commands.html">Management Commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li> <li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li>
@ -98,6 +96,19 @@
<div class="section" id="settings"> <div class="section" id="settings">
<span id="reference-settings"></span><h1>Settings<a class="headerlink" href="#settings" title="Permalink to this headline"></a></h1> <span id="reference-settings"></span><h1>Settings<a class="headerlink" href="#settings" title="Permalink to this headline"></a></h1>
<p>The <tt class="docutils literal"><span class="pre">CATEGORIES_SETTINGS</span></tt> dictionary is where you can override the default settings. You don&#8217;t have to include all the settings; only the ones which you want to override.</p> <p>The <tt class="docutils literal"><span class="pre">CATEGORIES_SETTINGS</span></tt> dictionary is where you can override the default settings. You don&#8217;t have to include all the settings; only the ones which you want to override.</p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#allow-slug-change" id="id10">ALLOW_SLUG_CHANGE</a></li>
<li><a class="reference internal" href="#slug-transliterator" id="id11">SLUG_TRANSLITERATOR</a></li>
<li><a class="reference internal" href="#cache-view-length" id="id12">CACHE_VIEW_LENGTH</a></li>
<li><a class="reference internal" href="#relation-models" id="id13">RELATION_MODELS</a></li>
<li><a class="reference internal" href="#m2m-registry" id="id14">M2M_REGISTRY</a></li>
<li><a class="reference internal" href="#fk-registry" id="id15">FK_REGISTRY</a></li>
<li><a class="reference internal" href="#thumbnail-upload-path" id="id16">THUMBNAIL_UPLOAD_PATH</a></li>
<li><a class="reference internal" href="#thumbnail-storage" id="id17">THUMBNAIL_STORAGE</a></li>
<li><a class="reference internal" href="#javascript-url" id="id18">JAVASCRIPT_URL</a></li>
</ul>
</div>
<p>The default settings are:</p> <p>The default settings are:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">CATEGORIES_SETTINGS</span> <span class="o">=</span> <span class="p">{</span> <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">&#39;ALLOW_SLUG_CHANGE&#39;</span><span class="p">:</span> <span class="bp">False</span><span class="p">,</span> <span class="s">&#39;ALLOW_SLUG_CHANGE&#39;</span><span class="p">:</span> <span class="bp">False</span><span class="p">,</span>
@ -107,46 +118,53 @@
<span class="s">&#39;FK_REGISTRY&#39;</span><span class="p">:</span> <span class="p">{},</span> <span class="s">&#39;FK_REGISTRY&#39;</span><span class="p">:</span> <span class="p">{},</span>
<span class="s">&#39;THUMBNAIL_UPLOAD_PATH&#39;</span><span class="p">:</span> <span class="s">&#39;uploads/categories/thumbnails&#39;</span><span class="p">,</span> <span class="s">&#39;THUMBNAIL_UPLOAD_PATH&#39;</span><span class="p">:</span> <span class="s">&#39;uploads/categories/thumbnails&#39;</span><span class="p">,</span>
<span class="s">&#39;THUMBNAIL_STORAGE&#39;</span><span class="p">:</span> <span class="n">settings</span><span class="o">.</span><span class="n">DEFAULT_FILE_STORAGE</span><span class="p">,</span> <span class="s">&#39;THUMBNAIL_STORAGE&#39;</span><span class="p">:</span> <span class="n">settings</span><span class="o">.</span><span class="n">DEFAULT_FILE_STORAGE</span><span class="p">,</span>
<span class="s">&#39;SLUG_TRANSLITERATOR&#39;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">,</span>
<span class="p">}</span> <span class="p">}</span>
</pre></div> </pre></div>
</div> </div>
<div class="section" id="allow-slug-change"> <div class="section" id="allow-slug-change">
<h2>ALLOW_SLUG_CHANGE<a class="headerlink" href="#allow-slug-change" title="Permalink to this headline"></a></h2> <span id="id1"></span><h2><a class="toc-backref" href="#id10">ALLOW_SLUG_CHANGE</a><a class="headerlink" href="#allow-slug-change" title="Permalink to this headline"></a></h2>
<p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">False</span></tt></p> <p><strong>Default:</strong> <tt class="xref docutils literal"><span class="pre">False</span></tt></p>
<p><strong>Description:</strong> Changing the slug for a category can have serious consequences if it is used as part of a URL. Setting this to <tt class="docutils literal"><span class="pre">True</span></tt> will allow users to change the slug of a category.</p> <p><strong>Description:</strong> Changing the slug for a category can have serious consequences if it is used as part of a URL. Setting this to <tt class="xref docutils literal"><span class="pre">True</span></tt> will allow users to change the slug of a category.</p>
</div>
<div class="section" id="slug-transliterator">
<span id="id2"></span><h2><a class="toc-backref" href="#id11">SLUG_TRANSLITERATOR</a><a class="headerlink" href="#slug-transliterator" title="Permalink to this headline"></a></h2>
<p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">lambda</span> <span class="pre">x:</span> <span class="pre">x</span></tt></p>
<p><strong>Description:</strong> Allows the specification of a function to convert non-ASCII characters in the potential slug to ASCII characters. Allows specifying a <tt class="docutils literal"><span class="pre">callable()</span></tt> or a string in the form of <tt class="docutils literal"><span class="pre">'path.to.module.function'</span></tt>.</p>
<p>A great tool for this is <a class="reference external" href="http://pypi.python.org/pypi/Unidecode">Unidecode</a>. Use it by setting <tt class="docutils literal"><span class="pre">SLUG_TRANSLITERATOR</span></tt> to <tt class="docutils literal"><span class="pre">'unidecode.unidecode</span></tt>.</p>
</div> </div>
<div class="section" id="cache-view-length"> <div class="section" id="cache-view-length">
<h2>CACHE_VIEW_LENGTH<a class="headerlink" href="#cache-view-length" title="Permalink to this headline"></a></h2> <span id="id3"></span><h2><a class="toc-backref" href="#id12">CACHE_VIEW_LENGTH</a><a class="headerlink" href="#cache-view-length" title="Permalink to this headline"></a></h2>
<p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">0</span></tt></p> <p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">0</span></tt></p>
<p><strong>Description:</strong> This setting will be deprecated soon, but in the mean time, it allows you to specify the amount of time each view result is cached.</p> <p><strong>Description:</strong> This setting will be deprecated soon, but in the mean time, it allows you to specify the amount of time each view result is cached.</p>
</div> </div>
<div class="section" id="relation-models"> <div class="section" id="relation-models">
<h2>RELATION_MODELS<a class="headerlink" href="#relation-models" title="Permalink to this headline"></a></h2> <span id="id4"></span><h2><a class="toc-backref" href="#id13">RELATION_MODELS</a><a class="headerlink" href="#relation-models" title="Permalink to this headline"></a></h2>
<p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">[]</span></tt></p> <p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">[]</span></tt></p>
<p><strong>Description:</strong> Relation models is a set of models that a user can associate with this category. You specify models using <tt class="docutils literal"><span class="pre">'app_name.modelname'</span></tt> syntax.</p> <p><strong>Description:</strong> Relation models is a set of models that a user can associate with this category. You specify models using <tt class="docutils literal"><span class="pre">'app_name.modelname'</span></tt> syntax.</p>
</div> </div>
<div class="section" id="m2m-registry"> <div class="section" id="m2m-registry">
<h2>M2M_REGISTRY<a class="headerlink" href="#m2m-registry" title="Permalink to this headline"></a></h2> <span id="id5"></span><h2><a class="toc-backref" href="#id14">M2M_REGISTRY</a><a class="headerlink" href="#m2m-registry" title="Permalink to this headline"></a></h2>
<p><strong>Default:</strong> {}</p> <p><strong>Default:</strong> {}</p>
<p><strong>Description:</strong> A dictionary where the keys are in <tt class="docutils literal"><span class="pre">'app_name.model_name'</span></tt> syntax, and the values are a string, dict, or tuple of dicts. See <a class="reference internal" href="../registering_models.html#registering-models"><em>Registering Models</em></a>.</p> <p><strong>Description:</strong> A dictionary where the keys are in <tt class="docutils literal"><span class="pre">'app_name.model_name'</span></tt> syntax, and the values are a string, dict, or tuple of dicts. See <a class="reference internal" href="../registering_models.html#registering-models"><em>Registering Models</em></a>.</p>
</div> </div>
<div class="section" id="fk-registry"> <div class="section" id="fk-registry">
<h2>FK_REGISTRY<a class="headerlink" href="#fk-registry" title="Permalink to this headline"></a></h2> <span id="id6"></span><h2><a class="toc-backref" href="#id15">FK_REGISTRY</a><a class="headerlink" href="#fk-registry" title="Permalink to this headline"></a></h2>
<p><strong>Default:</strong> {}</p> <p><strong>Default:</strong> {}</p>
<p><strong>Description:</strong> A dictionary where the keys are in <tt class="docutils literal"><span class="pre">'app_name.model_name'</span></tt> syntax, and the values are a string, dict, or tuple of dicts. See <a class="reference internal" href="../registering_models.html#registering-models"><em>Registering Models</em></a>.</p> <p><strong>Description:</strong> A dictionary where the keys are in <tt class="docutils literal"><span class="pre">'app_name.model_name'</span></tt> syntax, and the values are a string, dict, or tuple of dicts. See <a class="reference internal" href="../registering_models.html#registering-models"><em>Registering Models</em></a>.</p>
</div> </div>
<div class="section" id="thumbnail-upload-path"> <div class="section" id="thumbnail-upload-path">
<h2>THUMBNAIL_UPLOAD_PATH<a class="headerlink" href="#thumbnail-upload-path" title="Permalink to this headline"></a></h2> <span id="id7"></span><h2><a class="toc-backref" href="#id16">THUMBNAIL_UPLOAD_PATH</a><a class="headerlink" href="#thumbnail-upload-path" title="Permalink to this headline"></a></h2>
<p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">'uploads/categories/thumbnails'</span></tt></p> <p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">'uploads/categories/thumbnails'</span></tt></p>
<p><strong>Description:</strong> Where thumbnails for the categories will be saved.</p> <p><strong>Description:</strong> Where thumbnails for the categories will be saved.</p>
</div> </div>
<div class="section" id="thumbnail-storage"> <div class="section" id="thumbnail-storage">
<h2>THUMBNAIL_STORAGE<a class="headerlink" href="#thumbnail-storage" title="Permalink to this headline"></a></h2> <span id="id8"></span><h2><a class="toc-backref" href="#id17">THUMBNAIL_STORAGE</a><a class="headerlink" href="#thumbnail-storage" title="Permalink to this headline"></a></h2>
<p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">settings.DEFAULT_FILE_STORAGE</span></tt></p> <p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">settings.DEFAULT_FILE_STORAGE</span></tt></p>
<p><strong>Description:</strong> How to store the thumbnails. Allows for external storage engines like S3.</p> <p><strong>Description:</strong> How to store the thumbnails. Allows for external storage engines like S3.</p>
</div> </div>
<div class="section" id="javascript-url"> <div class="section" id="javascript-url">
<h2>JAVASCRIPT_URL<a class="headerlink" href="#javascript-url" title="Permalink to this headline"></a></h2> <span id="id9"></span><h2><a class="toc-backref" href="#id18">JAVASCRIPT_URL</a><a class="headerlink" href="#javascript-url" title="Permalink to this headline"></a></h2>
<p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">STATIC_URL</span> <span class="pre">or</span> <span class="pre">MEDIA_URL</span> <span class="pre">+</span> <span class="pre">'js/'</span></tt></p> <p><strong>Default:</strong> <tt class="docutils literal"><span class="pre">STATIC_URL</span> <span class="pre">or</span> <span class="pre">MEDIA_URL</span> <span class="pre">+</span> <span class="pre">'js/'</span></tt></p>
<p><strong>Description:</strong> Allows for customization of javascript placement.</p> <p><strong>Description:</strong> Allows for customization of javascript placement.</p>
</div> </div>
@ -159,7 +177,7 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Template Tags &mdash; Django Categories 0.8.8 documentation</title> <title>Template Tags &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../', URL_ROOT: '../',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,13 +21,13 @@
<script type="text/javascript" src="../_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="../index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="../index.html" />
<link rel="up" title="Reference" href="index.html" /> <link rel="up" title="Reference" href="index.html" />
<link rel="prev" title="Settings" href="settings.html" /> <link rel="prev" title="Settings" href="settings.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Template Tags</h1></div> <div id="title"><h1>Template Tags</h1></div>
@ -52,6 +49,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="../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="../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="../adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="../custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Reference</a><ul class="current"> <li class="toctree-l1 current"><a class="reference internal" href="index.html">Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="management_commands.html">Management Commands</a></li> <li class="toctree-l2"><a class="reference internal" href="management_commands.html">Management Commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li> <li class="toctree-l2"><a class="reference internal" href="models.html">Models</a></li>
@ -208,7 +206,7 @@ as an iterable.</p>
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registering Models &mdash; Django Categories 0.8.8 documentation</title> <title>Registering Models &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '', URL_ROOT: '',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,13 +21,13 @@
<script type="text/javascript" src="_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="index.html" />
<link rel="next" title="Adding the fields to the database" href="adding_the_fields.html" /> <link rel="next" title="Adding the fields to the database" href="adding_the_fields.html" />
<link rel="prev" title="Using categories in templates" href="usage.html" /> <link rel="prev" title="Using categories in templates" href="usage.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Registering Models</h1></div> <div id="title"><h1>Registering Models</h1></div>
@ -58,6 +55,7 @@
</ul> </ul>
</li> </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="adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
</ul> </ul>
@ -177,7 +175,7 @@
<col class="field-name" /> <col class="field-name" />
<col class="field-body" /> <col class="field-body" />
<tbody valign="top"> <tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>model</strong> &#8211; The Django Model to link to Django Categories</li> <li><strong>model</strong> &#8211; The Django Model to link to Django Categories</li>
<li><strong>field_name</strong> &#8211; Optional name for the field <strong>default:</strong> category</li> <li><strong>field_name</strong> &#8211; Optional name for the field <strong>default:</strong> category</li>
<li><strong>extra_params</strong> &#8211; Optional dictionary of extra parameters passed to the <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> class.</li> <li><strong>extra_params</strong> &#8211; Optional dictionary of extra parameters passed to the <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> class.</li>
@ -211,7 +209,7 @@
<col class="field-name" /> <col class="field-name" />
<col class="field-body" /> <col class="field-body" />
<tbody valign="top"> <tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>model</strong> &#8211; The Django Model to link to Django Categories</li> <li><strong>model</strong> &#8211; The Django Model to link to Django Categories</li>
<li><strong>field_name</strong> &#8211; Optional name for the field <strong>default:</strong> categories</li> <li><strong>field_name</strong> &#8211; Optional name for the field <strong>default:</strong> categories</li>
<li><strong>extra_params</strong> &#8211; Optional dictionary of extra parameters passed to the <tt class="docutils literal"><span class="pre">ManyToManyField</span></tt> class.</li> <li><strong>extra_params</strong> &#8211; Optional dictionary of extra parameters passed to the <tt class="docutils literal"><span class="pre">ManyToManyField</span></tt> class.</li>
@ -237,7 +235,7 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search &mdash; Django Categories 0.8.8 documentation</title> <title>Search &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '', URL_ROOT: '',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -25,7 +22,7 @@
<script type="text/javascript" src="_static/underscore.js"></script> <script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/searchtools.js"></script> <script type="text/javascript" src="_static/searchtools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="index.html" />
<script type="text/javascript"> <script type="text/javascript">
jQuery(function() { Search.loadIndex("searchindex.js"); }); jQuery(function() { Search.loadIndex("searchindex.js"); });
</script> </script>
@ -34,7 +31,7 @@
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Search</h1></div> <div id="title"><h1>Search</h1></div>
@ -55,6 +52,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="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="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="adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
</ul> </ul>
@ -98,7 +96,7 @@
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

File diff suppressed because one or more lines are too long

View file

@ -2,20 +2,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Using categories in templates &mdash; Django Categories 0.8.8 documentation</title> <title>Using categories in templates &mdash; Django Categories v1.0b1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
var DOCUMENTATION_OPTIONS = { var DOCUMENTATION_OPTIONS = {
URL_ROOT: '', URL_ROOT: '',
VERSION: '0.8.8', VERSION: '1.0b1',
COLLAPSE_INDEX: false, COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html', FILE_SUFFIX: '.html',
HAS_SOURCE: true HAS_SOURCE: true
@ -24,13 +21,13 @@
<script type="text/javascript" src="_static/jquery.js"></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/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Django Categories 0.8.8 documentation" href="index.html" /> <link rel="top" title="Django Categories v1.0b1 documentation" href="index.html" />
<link rel="next" title="Registering Models" href="registering_models.html" /> <link rel="next" title="Registering Models" href="registering_models.html" />
<link rel="prev" title="Getting Started" href="getting_started.html" /> <link rel="prev" title="Getting Started" href="getting_started.html" />
</head> </head>
<body> <body>
<div id="docstitle"> <div id="docstitle">
<p>Django Categories 0.8.8 documentation</p> <p>Django Categories v1.0b1 documentation</p>
</div> </div>
<div id="header"> <div id="header">
<div id="title"><h1>Using categories in templates</h1></div> <div id="title"><h1>Using categories in templates</h1></div>
@ -57,6 +54,7 @@
</li> </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="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="adding_the_fields.html">Adding the fields to the database</a></li>
<li class="toctree-l1"><a class="reference internal" href="custom_categories.html">Creating Custom Categories</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
</ul> </ul>
@ -96,8 +94,8 @@
<h1>Using categories in templates<a class="headerlink" href="#using-categories-in-templates" title="Permalink to this headline"></a></h1> <h1>Using categories in templates<a class="headerlink" href="#using-categories-in-templates" title="Permalink to this headline"></a></h1>
<div class="section" id="getting-all-items-within-a-category"> <div class="section" id="getting-all-items-within-a-category">
<h2>Getting all items within a category<a class="headerlink" href="#getting-all-items-within-a-category" title="Permalink to this headline"></a></h2> <h2>Getting all items within a category<a class="headerlink" href="#getting-all-items-within-a-category" title="Permalink to this headline"></a></h2>
<p>The <tt class="xref py py-class docutils literal"><span class="pre">Category</span></tt> model automatically gets <a class="reference external" href="https://docs.djangoproject.com/en/1.3/topics/db/queries/#following-relationships-backward">reverse relationships</a> with all other models related to it.</p> <p>The <a class="reference internal" href="reference/models.html#Category" title="Category"><tt class="xref py py-class docutils literal"><span class="pre">Category</span></tt></a> model automatically gets <a class="reference external" href="https://docs.djangoproject.com/en/1.3/topics/db/queries/#following-relationships-backward">reverse relationships</a> with all other models related to it.</p>
<p>This allows you access to the related objects from the template without altering any views. For example, if you only had <tt class="docutils literal"><span class="pre">Entry</span></tt> models related to <tt class="xref py py-class docutils literal"><span class="pre">Category</span></tt>, your <tt class="docutils literal"><span class="pre">categories/category_detail.html</span></tt> template could look like</p> <p>This allows you access to the related objects from the template without altering any views. For example, if you only had <tt class="docutils literal"><span class="pre">Entry</span></tt> models related to <a class="reference internal" href="reference/models.html#Category" title="Category"><tt class="xref py py-class docutils literal"><span class="pre">Category</span></tt></a>, your <tt class="docutils literal"><span class="pre">categories/category_detail.html</span></tt> template could look like</p>
<div class="highlight-django"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1 <div class="highlight-django"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2 2
3 3
@ -169,21 +167,21 @@ two-tuples of the current tree item and a <tt class="docutils literal"><span cla
information about the tree structure around the item, with the following information about the tree structure around the item, with the following
keys:</p> keys:</p>
<blockquote> <blockquote>
<div><dl class="docutils"> <dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">'new_level'</span></tt></dt> <dt><tt class="docutils literal"><span class="pre">'new_level'</span></tt></dt>
<dd><tt class="docutils literal"><span class="pre">True</span></tt> if the current item is the start of a new level in <dd><tt class="xref docutils literal"><span class="pre">True</span></tt> if the current item is the start of a new level in
the tree, <tt class="docutils literal"><span class="pre">False</span></tt> otherwise.</dd> the tree, <tt class="xref docutils literal"><span class="pre">False</span></tt> otherwise.</dd>
<dt><tt class="docutils literal"><span class="pre">'closed_levels'</span></tt></dt> <dt><tt class="docutils literal"><span class="pre">'closed_levels'</span></tt></dt>
<dd>A list of levels which end after the current item. This will <dd>A list of levels which end after the current item. This will
be an empty list if the next item&#8217;s level is the same as or be an empty list if the next item&#8217;s level is the same as or
greater than the level of the current item.</dd> greater than the level of the current item.</dd>
</dl> </dl>
</div></blockquote> </blockquote>
<p>An optional argument can be provided to specify extra details about the <p>An optional argument can be provided to specify extra details about the
structure which should appear in the <tt class="docutils literal"><span class="pre">dict</span></tt>. This should be a structure which should appear in the <tt class="docutils literal"><span class="pre">dict</span></tt>. This should be a
comma-separated list of feature names. The valid feature names are:</p> comma-separated list of feature names. The valid feature names are:</p>
<blockquote> <blockquote>
<div><dl class="docutils"> <dl class="docutils">
<dt>ancestors</dt> <dt>ancestors</dt>
<dd><p class="first">Adds a list of unicode representations of the ancestors of the <dd><p class="first">Adds a list of unicode representations of the ancestors of the
current node, in descending order (root node first, immediate current node, in descending order (root node first, immediate
@ -197,7 +195,7 @@ on the right:</p>
</div> </div>
</dd> </dd>
</dl> </dl>
</div></blockquote> </blockquote>
</div> </div>
</div> </div>
</div> </div>
@ -209,7 +207,7 @@ on the right:</p>
<div class="footer"> <div class="footer">
<p> <p>
&copy; Copyright 2010-2012, Corey Oordt. &copy; Copyright 2010-2012, Corey Oordt.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
</p> </p>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>

View file

@ -10,7 +10,6 @@ from categories.admin import CategoryBaseAdmin, CategoryBaseAdminForm
class SimpleCategoryAdminForm(CategoryBaseAdminForm): class SimpleCategoryAdminForm(CategoryBaseAdminForm):
class Meta: class Meta:
model = SimpleCategory model = SimpleCategory
verbose_name_plural = 'Simple Categories'
class SimpleCategoryAdmin(CategoryBaseAdmin): class SimpleCategoryAdmin(CategoryBaseAdmin):
form = SimpleCategoryAdminForm form = SimpleCategoryAdminForm