From 9528f971c97e9f560457dafb84fadb6c2cb8bc81 Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Sat, 7 May 2011 20:33:00 -0400 Subject: [PATCH] Fixing stashing conflict --- CREDITS.txt | 10 +++ README.rst | 9 +++ categories/fields.py | 7 +++ categories/settings.py | 47 ++++++++++++--- doc_src/index.rst | 1 + doc_src/registering_models.rst | 87 +++++++++++++++++++++++++++ docs/.buildinfo | 2 +- docs/_sources/index.txt | 1 + docs/_sources/registering_models.txt | 62 +++++++++++++++++++ docs/genindex.html | 9 +-- docs/getting_started.html | 8 +-- docs/index.html | 14 +++-- docs/objects.inv | Bin 263 -> 266 bytes docs/registering_models.html | 60 ++++++++++++++++-- docs/search.html | 9 +-- docs/searchindex.js | 2 +- docs/templatetags.html | 8 +-- docs/usage.html | 8 +-- 18 files changed, 307 insertions(+), 37 deletions(-) diff --git a/CREDITS.txt b/CREDITS.txt index e69de29..4d45050 100644 --- a/CREDITS.txt +++ b/CREDITS.txt @@ -0,0 +1,10 @@ +Corey Oordt github.com/coordt +Erik Simmler github.com/tgecho +martinogden githun.com/martinogden +Ramiro Morales github.com/ramiro +Evan Culver github.com/eculver +Andrzej Herok github.com/aherok +Jonathan Hensley +Justin Quick github.com/justquick +Josh Ourisman github.com/joshourisman +Jose Soares github.com/josesoa \ No newline at end of file diff --git a/README.rst b/README.rst index 7f0507a..c3e64dc 100644 --- a/README.rst +++ b/README.rst @@ -2,6 +2,15 @@ Django Categories grew out of our need to provide a basic hierarchical taxonomy As a news site, our stories, photos, and other content get divided into "sections" and we wanted all the apps to use the same set of sections. As our needs grew, the Django Categories grew in the functionality it gave to category handling within web pages. +New in 0.6 +========== + +**Class-based views** + Works great with Django 1.3 + +**New Settings infrastructure** + To be more like the Django project, we are migrating from individual CATEGORIES_* settings to a dictionary named ``CATEGORIES_SETTINGS``\ . Use of the previous settings will still work but will generate a ``PendingDeprecationError``\ . + Features of the project ======================= diff --git a/categories/fields.py b/categories/fields.py index f2cdb00..4941722 100644 --- a/categories/fields.py +++ b/categories/fields.py @@ -16,3 +16,10 @@ class CategoryFKField(ForeignKey): if 'to' in kwargs: kwargs.pop('to') super(CategoryFKField, self).__init__(to=Category, **kwargs) + +try: + from south.modelsinspector import add_introspection_rules + add_introspection_rules([], ["^categories\.fields\.CategoryFKField"]) + add_introspection_rules([], ["^categories\.fields\.CategoryM2MField"]) +except ImportError: + pass diff --git a/categories/settings.py b/categories/settings.py index dbda8e6..c240610 100644 --- a/categories/settings.py +++ b/categories/settings.py @@ -1,12 +1,45 @@ +import warnings + from django.conf import settings - -ALLOW_SLUG_CHANGE = getattr(settings, 'CATEGORIES_ALLOW_SLUG_CHANGE', False) - -CACHE_VIEW_LENGTH = getattr(settings, 'CATEGORIES_CACHE_VIEW_LENGTH', 3600) - from django.db.models import Q -DEFAULT_RELATION_MODELS = [] -RELATION_MODELS = getattr(settings, 'CATEGORIES_RELATION_MODELS', DEFAULT_RELATION_MODELS) or [] + +CATEGORIES_SETTINGS = { + 'ALLOW_SLUG_CHANGE': False, + 'CACHE_VIEW_LENGTH': 0, + 'RELATION_MODELS': [], + 'M2M_REGISTRY': [], + 'FK_REGISTRY': [] +} + +CATEGORIES_SETTINGS.update(getattr(settings, 'CATEGORIES_SETTINGS', {})) + +if hasattr(settings, 'CATEGORIES_ALLOW_SLUG_CHANGE'): + warnings.warn( + "settings.CATEGORIES_ALLOW_SLUG_CHANGE is deprecated; use settings.CATEGORIES_SETTINGS instead.", + DeprecationWarning + ) + ALLOW_SLUG_CHANGE = getattr(settings, 'CATEGORIES_ALLOW_SLUG_CHANGE') +else: + ALLOW_SLUG_CHANGE = CATEGORIES_SETTINGS['ALLOW_SLUG_CHANGE'] + +if hasattr(settings, 'CATEGORIES_CACHE_VIEW_LENGTH'): + warnings.warn( + "settings.CATEGORIES_CACHE_VIEW_LENGTH is deprecated; use settings.CATEGORIES_SETTINGS instead.", + DeprecationWarning + ) + CACHE_VIEW_LENGTH = getattr(settings, 'CATEGORIES_CACHE_VIEW_LENGTH') +else: + CACHE_VIEW_LENGTH = CATEGORIES_SETTINGS['CACHE_VIEW_LENGTH'] + +if hasattr(settings, 'CATEGORIES_RELATION_MODELS'): + warnings.warn( + "settings.CATEGORIES_RELATION_MODELS is deprecated; use settings.CATEGORIES_SETTINGS instead.", + DeprecationWarning + ) + RELATION_MODELS = getattr(settings, 'CATEGORIES_RELATION_MODELS') +else: + RELATION_MODELS = CATEGORIES_SETTINGS['RELATION_MODELS'] + RELATIONS = [Q(app_label=al, model=m) for al, m in [x.split('.') for x in RELATION_MODELS]] # For assigning a thumbnail to a category diff --git a/doc_src/index.rst b/doc_src/index.rst index 1adc49b..75142c0 100644 --- a/doc_src/index.rst +++ b/doc_src/index.rst @@ -14,6 +14,7 @@ Contents: usage registering_models templatetags + reference/index Indices and tables ================== diff --git a/doc_src/registering_models.rst b/doc_src/registering_models.rst index d3bf92b..a93be89 100644 --- a/doc_src/registering_models.rst +++ b/doc_src/registering_models.rst @@ -3,6 +3,93 @@ Registering Models ================== +Registering models in settings.py +================================= + +It is nice to not have to modify the code of applications to add a relation to categories. You can therefore do all the registering in ``settings.py``\ . For example: + +.. code-block:: python + + CATEGORIES_SETTINGS = { + 'FK_REGISTRY': { + 'app.AModel': 'category', + 'app.MyModel': ( + 'primary_category', + {'name': 'secondary_category', 'related_name': 'mymodel_sec_cat'}, ) + }, + 'M2M_REGISTRY': { + 'app.AModel': 'categories', + 'app.MyModel': ('other_categories', 'more_categories', ), + } + } + +The ``FK_REGISTRY`` is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings or dictionaries specifying the necessary information for each field. + +The ``M2M_REGISTRY`` is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings specifying the necessary information for each field. + + +Registering one Category field to model +*************************************** + +The simplest way is to specify the name of the field, such as: + +.. code-block:: python + + CATEGORIES_SETTINGS = { + 'FK_REGISTRY': { + 'app.AModel': 'category' + } + } + +This is equivalent to adding the following the ``AModel`` of ``app``\ : + +.. code-block:: python + + category = models.ForeignKey(Category) + + +If you want more control over the new field, you can use a dictionary and pass other ``ForeignKey`` options. The ``name`` key is required: + +.. code-block:: python + + CATEGORIES_SETTINGS = { + 'FK_REGISTRY': { + 'app.AModel': {'name': 'category', 'related_name': 'amodel_cats'} + } + } + +This is equivalent to adding the following the ``AModel`` of ``app``\ : + +.. code-block:: python + + category = models.ForeignKey(Category, related_name='amodel_cats') + +Registering two or more Category fields to a Model +************************************************** + +When you want more than one relation to ``Category``\ , all but one of the fields must specify a ``related_name`` to avoid conflicts, like so: + +.. code-block:: python + + CATEGORIES_SETTINGS = { + 'FK_REGISTRY': { + 'app.MyModel': ( + 'primary_category', + {'name': 'secondary_category', 'related_name': 'mymodel_sec_cat'}, ) + }, + +Registering one or more Many-to-Many Category fields to a Model +*************************************************************** + +.. code-block:: python + + CATEGORIES_SETTINGS = { + 'M2M_REGISTRY': { + 'app.AModel': 'categories', + 'app.MyModel': ('other_categories', 'more_categories', ), + } + } + Registering a many-to-one relationship ====================================== diff --git a/docs/.buildinfo b/docs/.buildinfo index 9ecba55..a22d42f 100644 --- a/docs/.buildinfo +++ b/docs/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: e4eb74933f8c18cbcf27c5697f36ee4a +config: 071e7273e6f47dab6004e15916a31efa tags: fbb0d17656682115ca4d033fb2f83ba1 diff --git a/docs/_sources/index.txt b/docs/_sources/index.txt index 1adc49b..75142c0 100644 --- a/docs/_sources/index.txt +++ b/docs/_sources/index.txt @@ -14,6 +14,7 @@ Contents: usage registering_models templatetags + reference/index Indices and tables ================== diff --git a/docs/_sources/registering_models.txt b/docs/_sources/registering_models.txt index d3bf92b..78fc844 100644 --- a/docs/_sources/registering_models.txt +++ b/docs/_sources/registering_models.txt @@ -3,6 +3,68 @@ Registering Models ================== +Registering models in settings.py +================================= + +It is nice to not have to modify the code of applications to add a relation to categories. You can therefore do all the registering in ``settings.py``\ . For example: + +.. code-block:: python + + CATEGORIES_SETTINGS = { + 'FK_REGISTRY': { + 'app.AModel': 'category', + 'app.MyModel': ( + 'primary_category', + {'name': 'secondary_category', 'related_name': 'mymodel_sec_cat'}, ) + }, + 'M2M_REGISTRY': { + 'app.AModel': 'categories', + 'app.MyModel': ('other_categories', 'more_categories', ), + } + } + +The ``FK_REGISTRY`` is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings or dictionaries specifying the necessary information for each field. + +The ``M2M_REGISTRY`` is a dictionary whose keys are the model to which to add the new field(s). The value is a string or tuple of strings specifying the necessary information for each field. + + +Registering One Category Field +****************************** + +The simplest way is to specify the name of the field, such as: + +.. code-block:: python + + CATEGORIES_SETTINGS = { + 'FK_REGISTRY': { + 'app.AModel': 'category' + } + } + +This is equivalent to adding the following the ``AModel`` of ``app``\ : + +.. code-block:: python + + category = models.ForeignKey(Category) + + +If you want more control over the new field, you can use a dictionary and pass other ``ForeignKey`` options: + +.. code-block:: python + + CATEGORIES_SETTINGS = { + 'FK_REGISTRY': { + 'app.AModel': {'name': 'category', 'related_name': 'amodel_cats'} + } + } + +This is equivalent to adding the following the ``AModel`` of ``app``\ : + +.. code-block:: python + + category = models.ForeignKey(Category, related_name='amodel_cats') + + Registering a many-to-one relationship ====================================== diff --git a/docs/genindex.html b/docs/genindex.html index a41799a..6903e33 100644 --- a/docs/genindex.html +++ b/docs/genindex.html @@ -6,13 +6,13 @@ - Index — Django Categories v0.4.8 documentation + Index — Django Categories v0.6beta1 documentation - +
-

Django Categories v0.4.8 documentation

+

Django Categories v0.6beta1 documentation