mirror of
https://github.com/jazzband/django-categories.git
synced 2026-05-20 05:11:53 +00:00
Merge branch '0.7'
This commit is contained in:
commit
90fb0f887b
55 changed files with 1637 additions and 132 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -12,3 +12,5 @@ media/css/*.r*.css
|
|||
doc_src/_build
|
||||
MANIFEST
|
||||
dist/
|
||||
.venv
|
||||
example/media/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
__version_info__ = {
|
||||
'major': 0,
|
||||
'minor': 6,
|
||||
'minor': 7,
|
||||
'micro': 0,
|
||||
'releaselevel': 'final',
|
||||
'serial': 1
|
||||
|
|
@ -17,7 +17,8 @@ def get_version():
|
|||
|
||||
__version__ = get_version()
|
||||
|
||||
registry = {}
|
||||
field_registry = {}
|
||||
model_registry = {}
|
||||
|
||||
try:
|
||||
import fields
|
||||
|
|
@ -30,7 +31,16 @@ try:
|
|||
"""
|
||||
pass
|
||||
|
||||
registry = {}
|
||||
# The field registry keeps track of the individual fields created.
|
||||
# {'app.model.field': Field(**extra_params)}
|
||||
# Useful for doing a schema migration
|
||||
field_registry = {}
|
||||
|
||||
# The model registry keeps track of which models have one or more fields
|
||||
# registered.
|
||||
# {'app': [model1, model2]}
|
||||
# Useful for admin alteration
|
||||
model_registry = {}
|
||||
|
||||
def register_m2m(model, field_name='categories', extra_params={}):
|
||||
return _register(model, field_name, extra_params, fields.CategoryM2MField)
|
||||
|
|
@ -39,16 +49,21 @@ try:
|
|||
return _register(model, field_name, extra_params, fields.CategoryFKField)
|
||||
|
||||
def _register(model, field_name, extra_params={}, field=fields.CategoryFKField):
|
||||
registry_name = "%s.%s" % (model.__name__, field_name)
|
||||
app_label = model._meta.app_label
|
||||
registry_name = ".".join((app_label, model.__name__, field_name)).lower()
|
||||
|
||||
if registry_name in registry:
|
||||
if registry_name in field_registry:
|
||||
return #raise AlreadyRegistered
|
||||
registry[registry_name] = model
|
||||
opts = model._meta
|
||||
try:
|
||||
opts.get_field(field_name)
|
||||
except FieldDoesNotExist:
|
||||
field(**extra_params).contribute_to_class(model, field_name)
|
||||
if app_label not in model_registry:
|
||||
model_registry[app_label] = []
|
||||
if model not in model_registry[app_label]:
|
||||
model_registry[app_label].append(model)
|
||||
field_registry[registry_name] = field(**extra_params)
|
||||
field_registry[registry_name].contribute_to_class(model, field_name)
|
||||
|
||||
from categories import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ from mptt.forms import TreeNodeChoiceField
|
|||
from editor.tree_editor import TreeEditor
|
||||
from genericcollection import GenericCollectionTabularInline
|
||||
|
||||
from settings import ALLOW_SLUG_CHANGE, RELATION_MODELS
|
||||
from categories import registry
|
||||
from settings import ALLOW_SLUG_CHANGE, RELATION_MODELS, JAVASCRIPT_URL
|
||||
from categories import model_registry
|
||||
from models import Category
|
||||
|
||||
class NullTreeNodeChoiceField(forms.ModelChoiceField):
|
||||
|
|
@ -85,7 +85,7 @@ class CategoryAdmin(TreeEditor, admin.ModelAdmin):
|
|||
'fields': ('parent', 'name', 'thumbnail')
|
||||
}),
|
||||
('Meta Data', {
|
||||
'fields': ('alternate_title', 'description', 'meta_keywords', 'meta_extra'),
|
||||
'fields': ('alternate_title', 'alternate_url', 'description', 'meta_keywords', 'meta_extra'),
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
('Advanced', {
|
||||
|
|
@ -97,14 +97,14 @@ class CategoryAdmin(TreeEditor, admin.ModelAdmin):
|
|||
inlines = [InlineCategoryRelation,]
|
||||
|
||||
class Media:
|
||||
js = (settings.STATIC_URL + 'js/genericcollections.js',)
|
||||
js = (JAVASCRIPT_URL + 'genericcollections.js',)
|
||||
|
||||
admin.site.register(Category, CategoryAdmin)
|
||||
|
||||
for model, modeladmin in admin.site._registry.items():
|
||||
if model in registry.values() and modeladmin.fieldsets:
|
||||
if model in model_registry.values() and modeladmin.fieldsets:
|
||||
fieldsets = getattr(modeladmin, 'fieldsets', ())
|
||||
fields = [cat.split('.')[1] for cat in registry if registry[cat] == model]
|
||||
fields = [cat.split('.')[2] for cat in model_registry if model_registry[cat] == model]
|
||||
# check each field to see if already defined
|
||||
for cat in fields:
|
||||
for k,v in fieldsets:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
from django.db.models.signals import post_syncdb
|
||||
from categories.migration import migrate_app
|
||||
|
||||
post_syncdb.connect(migrate_app)
|
||||
28
categories/management/commands/add_category_fields.py
Normal file
28
categories/management/commands/add_category_fields.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Alter one or more models' tables with the registered attributes
|
||||
"""
|
||||
help = "Alter the tables for all registered models, or just specified models"
|
||||
args = "[appname ...]"
|
||||
can_import_settings = True
|
||||
requires_model_validation = False
|
||||
|
||||
def handle(self, *args, **options):
|
||||
"""
|
||||
Alter the tables
|
||||
"""
|
||||
try:
|
||||
from south.db import db
|
||||
except ImportError:
|
||||
raise ImproperlyConfigured("South must be installed for this command to work")
|
||||
|
||||
from categories.migration import migrate_app
|
||||
from categories import model_registry
|
||||
if args:
|
||||
for app in args:
|
||||
migrate_app(app)
|
||||
else:
|
||||
for app in model_registry:
|
||||
migrate_app(app)
|
||||
26
categories/management/commands/drop_category_field.py
Normal file
26
categories/management/commands/drop_category_field.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Alter one or more models' tables with the registered attributes
|
||||
"""
|
||||
help = "Drop the given field from the given model's table"
|
||||
args = "appname modelname fieldname"
|
||||
can_import_settings = True
|
||||
requires_model_validation = False
|
||||
|
||||
def handle(self, *args, **options):
|
||||
"""
|
||||
Alter the tables
|
||||
"""
|
||||
try:
|
||||
from south.db import db
|
||||
except ImportError:
|
||||
raise ImproperlyConfigured("South must be installed for this command to work")
|
||||
|
||||
from categories.migration import drop_field
|
||||
from categories import model_registry
|
||||
if len(args) != 3:
|
||||
print "You must specify an Application name, a Model name and a Field name"
|
||||
|
||||
drop_field(*args)
|
||||
90
categories/migration.py
Normal file
90
categories/migration.py
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
from django.db import models
|
||||
from django.db.utils import DatabaseError
|
||||
|
||||
from south.db import db
|
||||
from south.signals import post_migrate
|
||||
from categories.fields import CategoryM2MField, CategoryFKField
|
||||
from categories.models import Category
|
||||
from categories import model_registry, field_registry
|
||||
|
||||
def migrate_app(app, *args, **kwargs):
|
||||
"""
|
||||
Migrate all models of this app registered
|
||||
"""
|
||||
# pull the information from the registry
|
||||
fields = [fld for fld in field_registry.keys() if fld.startswith(app)]
|
||||
|
||||
# call the south commands to add the fields/tables
|
||||
for fld in fields:
|
||||
app_name, model_name, field_name = fld.split('.')
|
||||
|
||||
# Table is typically appname_modelname, but it could be different
|
||||
# always best to be sure.
|
||||
mdl = models.get_model(app_name, model_name)
|
||||
|
||||
if isinstance(field_registry[fld], CategoryFKField):
|
||||
print "Adding ForeignKey %s to %s" % (field_name, model_name)
|
||||
try:
|
||||
db.start_transaction()
|
||||
table_name = mdl._meta.db_table
|
||||
field_registry[fld].default=-1
|
||||
db.add_column(table_name, field_name, field_registry[fld], keep_default=False)
|
||||
db.commit_transaction()
|
||||
except DatabaseError, e:
|
||||
db.rollback_transaction()
|
||||
if "already exists" in str(e):
|
||||
print "Already exists"
|
||||
else:
|
||||
raise e
|
||||
elif isinstance(field_registry[fld], CategoryM2MField):
|
||||
print "Adding Many2Many table between %s and %s" % (model_name, 'category')
|
||||
table_name = "%s_%s" % (mdl._meta.db_table, 'categories')
|
||||
try:
|
||||
db.start_transaction()
|
||||
db.create_table(table_name, (
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
|
||||
(model_name, models.ForeignKey(mdl, null=False)),
|
||||
('category', models.ForeignKey(Category, null=False))
|
||||
))
|
||||
db.create_unique(table_name, ['%s_id' % model_name, 'category_id'])
|
||||
db.commit_transaction()
|
||||
except DatabaseError, e:
|
||||
db.rollback_transaction()
|
||||
if "already exists" in str(e):
|
||||
print "Already exists"
|
||||
else:
|
||||
raise e
|
||||
|
||||
def drop_field(app_name, model_name, field_name):
|
||||
"""
|
||||
Drop the given field from the app's model
|
||||
"""
|
||||
# Table is typically appname_modelname, but it could be different
|
||||
# always best to be sure.
|
||||
mdl = models.get_model(app_name, model_name)
|
||||
|
||||
fld = "%s.%s.%s" % (app_name, model_name, field_name)
|
||||
|
||||
if isinstance(field_registry[fld], CategoryFKField):
|
||||
print "Dropping ForeignKey %s from %s" % (field_name, model_name)
|
||||
try:
|
||||
db.start_transaction()
|
||||
table_name = mdl._meta.db_table
|
||||
db.delete_column(table_name, field_name)
|
||||
db.commit_transaction()
|
||||
except DatabaseError, e:
|
||||
db.rollback_transaction()
|
||||
raise e
|
||||
elif isinstance(field_registry[fld], CategoryM2MField):
|
||||
print "Dropping Many2Many table between %s and %s" % (model_name, 'category')
|
||||
table_name = "%s_%s" % (mdl._meta.db_table, 'categories')
|
||||
try:
|
||||
db.start_transaction()
|
||||
db.delete_table(table_name, cascade=False)
|
||||
db.commit_transaction()
|
||||
except DatabaseError, e:
|
||||
db.rollback_transaction()
|
||||
raise e
|
||||
|
||||
|
||||
post_migrate.connect(migrate_app)
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
BEGIN;
|
||||
ALTER TABLE "categories_category" ADD COLUMN "alternate_title" varchar(100);
|
||||
ALTER TABLE "categories_category" ADD COLUMN "meta_keywords" varchar(255);
|
||||
ALTER TABLE "categories_category" ADD COLUMN "meta_extra" text;
|
||||
ALTER TABLE "categories_category" ALTER COLUMN "description" TYPE text;
|
||||
COMMIT;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
BEGIN;
|
||||
ALTER TABLE "categories_category" DROP COLUMN "alternate_title" varchar(100);
|
||||
ALTER TABLE "categories_category" DROP COLUMN "meta_keywords" varchar(255);
|
||||
ALTER TABLE "categories_category" DROP COLUMN "meta_extra" text;
|
||||
ALTER TABLE "categories_category" ALTER COLUMN "description" TYPE varchar(255);
|
||||
COMMIT;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
BEGIN;
|
||||
ALTER TABLE "categories_category" ADD COLUMN "description" varchar(255);
|
||||
COMMIT;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
BEGIN;
|
||||
ALTER TABLE "categories_category" ADD COLUMN "thumbnail" varchar(100);
|
||||
COMMIT;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
BEGIN;
|
||||
ALTER TABLE "categories_category" DROP COLUMN "description";
|
||||
COMMIT;
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
# encoding: utf-8
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
|
||||
# Adding field 'Category.alternate_url'
|
||||
db.add_column('categories_category', 'alternate_url', self.gf('django.db.models.fields.URLField')(default='', max_length=200, blank=True), keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
|
||||
# Deleting field 'Category.alternate_url'
|
||||
db.delete_column('categories_category', 'alternate_url')
|
||||
|
||||
|
||||
models = {
|
||||
'categories.category': {
|
||||
'Meta': {'ordering': "('tree_id', 'lft')", 'unique_together': "(('parent', 'name'),)", 'object_name': 'Category'},
|
||||
'alternate_title': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '100', 'blank': 'True'}),
|
||||
'alternate_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
|
||||
'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
|
||||
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
|
||||
'meta_extra': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
|
||||
'meta_keywords': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['categories.Category']"}),
|
||||
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
|
||||
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}),
|
||||
'thumbnail': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
|
||||
'thumbnail_height': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'thumbnail_width': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['categories']
|
||||
|
|
@ -34,8 +34,11 @@ class Category(MPTTModel):
|
|||
blank=True,
|
||||
default="",
|
||||
max_length=100,
|
||||
help_text="An alternative title to use on pages with this category."
|
||||
)
|
||||
help_text="An alternative title to use on pages with this category.")
|
||||
alternate_url = models.URLField(
|
||||
blank=True,
|
||||
verify_exists=False,
|
||||
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,
|
||||
|
|
@ -53,6 +56,8 @@ class Category(MPTTModel):
|
|||
|
||||
def get_absolute_url(self):
|
||||
"""Return a path"""
|
||||
if self.alternate_url:
|
||||
return self.alternate_url
|
||||
prefix = reverse('categories_tree_list')
|
||||
ancestors = list(self.get_ancestors()) + [self,]
|
||||
return prefix + '/'.join([force_unicode(i.slug) for i in ancestors]) + '/'
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ DEFAULT_SETTINGS = {
|
|||
'FK_REGISTRY': {},
|
||||
'THUMBNAIL_UPLOAD_PATH': 'uploads/categories/thumbnails',
|
||||
'THUMBNAIL_STORAGE': settings.DEFAULT_FILE_STORAGE,
|
||||
'JAVASCRIPT_URL': getattr(settings, 'STATIC_URL', settings.MEDIA_URL) + 'js/',
|
||||
}
|
||||
|
||||
DEFAULT_SETTINGS.update(getattr(settings, 'CATEGORIES_SETTINGS', {}))
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
<tr class="{% cycle row1,row2 %} {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}">
|
||||
<td class="original">
|
||||
{% if inline_admin_form.original or inline_admin_form.show_url %}<p>
|
||||
{% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
|
||||
{% if inline_admin_form.original %} {{ inline_admin_form.original.content_object }}{% endif %}
|
||||
{% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original.content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
|
||||
</p>{% endif %}
|
||||
{% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
from django import template
|
||||
from django.template import Library, Node, TemplateSyntaxError, \
|
||||
Variable, resolve_variable, VariableDoesNotExist, Context
|
||||
from categories.models import Category
|
||||
from mptt.utils import drilldown_tree_for_node
|
||||
from mptt.templatetags.mptt_tags import tree_path, tree_info
|
||||
|
|
@ -206,3 +208,95 @@ def get_top_level_categories(parser, token):
|
|||
"Usage: {%% %s as <variable> %%}" % bits[0]
|
||||
)
|
||||
return TopLevelCategoriesNode(bits[2])
|
||||
|
||||
def resolve(var, context):
|
||||
try:
|
||||
return var.resolve(context)
|
||||
except VariableDoesNotExist:
|
||||
try:
|
||||
return var.var
|
||||
except AttributeError:
|
||||
return var
|
||||
|
||||
def get_latest_objects_by_category(category, app_label, model_name, set_name,
|
||||
date_field='pub_date', num=15):
|
||||
m = get_model(app_label, model_name)
|
||||
if not isinstance(category, Category):
|
||||
category = Category.objects.get(slug=str(category))
|
||||
children = Category.objects.filter(parent=category)
|
||||
ids = []
|
||||
for cat in list(children) + [category]:
|
||||
if hasattr(cat, '%s_set' % set_name):
|
||||
ids.extend([x.pk for x in getattr(cat, '%s_set' % set_name).all()[:num]])
|
||||
|
||||
return m.objects.filter(pk__in=ids).order_by('-%s' % date_field)[:num]
|
||||
|
||||
class LatestObjectsNode(Node):
|
||||
def __init__(self, var_name, category, app_label, model_name, set_name,
|
||||
date_field='pub_date', num=15):
|
||||
"""Get latest objects of app_label.model_name"""
|
||||
self.category = Variable(category)
|
||||
self.app_label = Variable(app_label)
|
||||
self.model_name = Variable(model_name)
|
||||
self.set_name = Variable(set_name)
|
||||
self.date_field = Variable(date_field)
|
||||
self.num = Variable(num)
|
||||
self.var_name = var_name
|
||||
|
||||
def get_cache_key(self, category, app_label, model_name, set_name,
|
||||
date_field, num):
|
||||
"""Get the cache key"""
|
||||
key = 'latest_objects.%s' % '.'.join([category, app_label, model_name,
|
||||
set_name, date_field, num])
|
||||
|
||||
def render(self, context):
|
||||
"""Render this sucker"""
|
||||
category = resolve(self.category, context)
|
||||
app_label = resolve(self.app_label, context)
|
||||
model_name = resolve(self.model_name, context)
|
||||
set_name = resolve(self.set_name, context)
|
||||
date_field = resolve(self.date_field, context)
|
||||
num = resolve(self.num, context)
|
||||
|
||||
cache_key = self.get_cache_key(category, app_label, model_name, set_name,
|
||||
date_field, num)
|
||||
result = cache.get(cache_key)
|
||||
if not result:
|
||||
result = get_latest_objects_by_category(category, app_label, model_name,
|
||||
set_name, date_field, num)
|
||||
|
||||
cache.set(key, result, 300)
|
||||
context[self.var_name] = result
|
||||
|
||||
return ''
|
||||
|
||||
def do_get_latest_objects_by_category(parser, token):
|
||||
"""
|
||||
Get the latest objects by category
|
||||
|
||||
{% get_latest_objects_by_category category app_name model_name set_name [date_field] [number] as [var_name] %}
|
||||
"""
|
||||
proper_form = "{% get_latest_objects_by_category category app_name model_name set_name [date_field] [number] as [var_name] %}"
|
||||
bits = token.split_contents()
|
||||
|
||||
if bits[-2] != 'as':
|
||||
raise TemplateSyntaxError("%s tag shoud be in the form: %s" % (bits[0], proper_form))
|
||||
if len(bits) < 7:
|
||||
raise TemplateSyntaxError("%s tag shoud be in the form: %s" % (bits[0], proper_form))
|
||||
if len(bits) > 9:
|
||||
raise TemplateSyntaxError("%s tag shoud be in the form: %s" % (bits[0], proper_form))
|
||||
category = bits[1]
|
||||
app_label = bits[2]
|
||||
model_name = bits[3]
|
||||
set_name = bits[4]
|
||||
var_name = bits[-1]
|
||||
if bits[5] != 'as':
|
||||
date_field = bits[5]
|
||||
else:
|
||||
date_field = None
|
||||
if bits[6] != 'as':
|
||||
num = bits[6]
|
||||
else:
|
||||
num = None
|
||||
return LatestObjectsNode(var_name, category, app_label, model_name, set_name,
|
||||
date_field, num)
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXOPTS = -a
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
|
|
|||
23
doc_src/adding_the_fields.rst
Normal file
23
doc_src/adding_the_fields.rst
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
.. _adding_the_fields:
|
||||
|
||||
=================================
|
||||
Adding the fields to the database
|
||||
=================================
|
||||
|
||||
While Django will create the appropriate columns and tables if you configure Django Categories first, many times that is not possible. You could also reset the table, but you would loose all data in it. There is another way.
|
||||
|
||||
Enter South
|
||||
***********
|
||||
|
||||
`South <http://south.aeracode.org/>`_ is a Django application for managing database schema changes. South's default behavior is for managing permanent changes to a model's structure. In the case of dynamically adding a field or fields to a model, this doesn't work because you are not making the change permanent. And probably don't want to.
|
||||
|
||||
Django Categories has a management command to create any missing fields. It requires South because it uses the South's API for making changes to databases. The management command is simple: ``python manage.py add_category_fields [app]``\ . If you do not include an app name, it will attempt to do all applications configured.
|
||||
|
||||
Running this command several times will not hurt any data or cause any errors.
|
||||
|
||||
Reconfiguring Fields
|
||||
********************
|
||||
|
||||
You can make changes to the field configurations as long as they do not change the underlying database structure. For example, adding a ``related_name`` (see :ref:`registering_a_m2one_relationship`\ ) because it only affects Django code. Changing the name of the field, however, is a different matter.
|
||||
|
||||
Django Categories provides a complementary management command to drop a field from the database (the field must still be in the configuration to do so): ``python manage.py drop_category_field app_name model_name field_name``
|
||||
|
|
@ -35,6 +35,35 @@ You can't do it as both at the same time, though.
|
|||
Connecting your model with Django-Categories
|
||||
============================================
|
||||
|
||||
Because there are a few additional methods and attributes that your model needs, you can't simply create a ``ForeignKey`` to ``Category``, even though that is eventually what happens.
|
||||
There are two ways to add Category fields to an application. If you are in control of the code (it's your application) or you are willing to take control of the code (fork someone else's app) you can make a :ref:`hard_coded_connection`\ .
|
||||
|
||||
For 3rd-party apps or even your own apps that you don't wish to add Django-Categories as a dependency, you can configure a :ref:`lazy_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.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from django.db import models
|
||||
|
||||
class MyModel(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
category = models.ForeignKey('categories.Category')
|
||||
|
||||
Don't forget to add the field or fields to your ``ModelAdmin`` class as well.
|
||||
|
||||
|
||||
.. _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.
|
||||
|
||||
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`\ .
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
===========================================
|
||||
Django Categories v|version| documentation!
|
||||
===========================================
|
||||
|
||||
|
||||
=============================
|
||||
Django Categories v |version|
|
||||
=============================
|
||||
|
||||
Contents:
|
||||
|
||||
|
|
@ -13,7 +11,7 @@ Contents:
|
|||
getting_started
|
||||
usage
|
||||
registering_models
|
||||
templatetags
|
||||
adding_the_fields
|
||||
reference/index
|
||||
|
||||
Indices and tables
|
||||
|
|
|
|||
|
|
@ -6,4 +6,7 @@ Reference
|
|||
:maxdepth: 2
|
||||
:glob:
|
||||
|
||||
settings
|
||||
management_commands
|
||||
models
|
||||
settings
|
||||
templatetags
|
||||
|
|
|
|||
38
doc_src/reference/management_commands.rst
Normal file
38
doc_src/reference/management_commands.rst
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
.. _management-commands:
|
||||
|
||||
===================
|
||||
Management Commands
|
||||
===================
|
||||
|
||||
.. _import_categories:
|
||||
|
||||
import_categories
|
||||
=================
|
||||
|
||||
**Usage:** ``./manage.py import_categories /path/to/file.txt [/path/to/file2.txt]``
|
||||
|
||||
Imports category tree(s) from a file. Sub categories must be indented by the same multiple of spaces or tabs. The first line in the file cannot start with a space or tab and you can't mix spaces and tabs.
|
||||
|
||||
|
||||
.. _add_category_fields:
|
||||
|
||||
add_category_fields
|
||||
===================
|
||||
|
||||
**Usage:** ``./manage.py add_category_fields [app1 app2 ...]``
|
||||
|
||||
Add missing registered category fields to the database table of a specified application or all registered applications.
|
||||
|
||||
Requires Django South.
|
||||
|
||||
|
||||
.. _drop_category_field:
|
||||
|
||||
drop_category_field
|
||||
===================
|
||||
|
||||
**Usage:** ``./manage.py drop_category_field app_name model_name field_name``
|
||||
|
||||
Drop the ``field_name`` field from the ``app_name_model_name`` table, if the field is currently registered in ``CATEGORIES_SETTINGS``\ .
|
||||
|
||||
Requires Django South.
|
||||
42
doc_src/reference/models.rst
Normal file
42
doc_src/reference/models.rst
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
======
|
||||
Models
|
||||
======
|
||||
|
||||
Category
|
||||
========
|
||||
|
||||
**parent**
|
||||
The category's parent category. Leave this blank for an Category Tree.
|
||||
|
||||
**name**
|
||||
The name of the category.
|
||||
|
||||
**thumbnail**
|
||||
An optional thumbnail, that is uploaded to ``CATEGORY_SETTINGS['THUMBNAIL_UPLOAD_PATH']`` via ``CATEGORY_SETTINGS['THUMBNAIL_STORAGE']``\ .
|
||||
|
||||
**thumbnail_width**
|
||||
The thumbnail width.
|
||||
|
||||
**thumbnail_height**
|
||||
The thumbnail height.
|
||||
|
||||
**order**
|
||||
The order of this category in the listing
|
||||
|
||||
**slug**
|
||||
A slug created from the name field
|
||||
|
||||
**alternate_title**
|
||||
An alternative title to use on pages with this category.
|
||||
|
||||
**alternate_url**
|
||||
An alternative URL to use instead of the one derived from the category hierarchy.
|
||||
|
||||
**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>``
|
||||
|
|
@ -67,4 +67,11 @@ THUMBNAIL_STORAGE
|
|||
|
||||
**Default:** ``settings.DEFAULT_FILE_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
|
||||
==============
|
||||
|
||||
**Default:** ``STATIC_URL or MEDIA_URL + 'js/'``
|
||||
|
||||
**Description:** Allows for customization of javascript placement.
|
||||
|
|
@ -95,6 +95,8 @@ Registering one or more Many-to-Many Category fields to a Model
|
|||
}
|
||||
}
|
||||
|
||||
.. _registering_a_m2one_relationship:
|
||||
|
||||
Registering a many-to-one relationship
|
||||
======================================
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Sphinx build info version 1
|
||||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
|
||||
config: 0f579989dd4cbe4af0af63fb63e64641
|
||||
tags: fbb0d17656682115ca4d033fb2f83ba1
|
||||
config:
|
||||
tags:
|
||||
|
|
|
|||
23
docs/_sources/adding_the_fields.txt
Normal file
23
docs/_sources/adding_the_fields.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
.. _adding_the_fields:
|
||||
|
||||
=================================
|
||||
Adding the fields to the database
|
||||
=================================
|
||||
|
||||
While Django will create the appropriate columns and tables if you configure Django Categories first, many times that is not possible. You could also reset the table, but you would loose all data in it. There is another way.
|
||||
|
||||
Enter South
|
||||
***********
|
||||
|
||||
`South <http://south.aeracode.org/>`_ is a Django application for managing database schema changes. South's default behavior is for managing permanent changes to a model's structure. In the case of dynamically adding a field or fields to a model, this doesn't work because you are not making the change permanent. And probably don't want to.
|
||||
|
||||
Django Categories has a management command to create any missing fields. It requires South because it uses the South's API for making changes to databases. The management command is simple: ``python manage.py add_category_fields [app]``\ . If you do not include an app name, it will attempt to do all applications configured.
|
||||
|
||||
Running this command several times will not hurt any data or cause any errors.
|
||||
|
||||
Reconfiguring Fields
|
||||
********************
|
||||
|
||||
You can make changes to the field configurations as long as they do not change the underlying database structure. For example, adding a ``related_name`` (see :ref:`registering_a_m2one_relationship`\ ) because it only affects Django code. Changing the name of the field, however, is a different matter.
|
||||
|
||||
Django Categories provides a complementary management command to drop a field from the database (the field must still be in the configuration to do so): ``python manage.py drop_category_field app_name model_name field_name``
|
||||
|
|
@ -35,6 +35,35 @@ You can't do it as both at the same time, though.
|
|||
Connecting your model with Django-Categories
|
||||
============================================
|
||||
|
||||
Because there are a few additional methods and attributes that your model needs, you can't simply create a ``ForeignKey`` to ``Category``, even though that is eventually what happens.
|
||||
There are two ways to add Category fields to an application. If you are in control of the code (it's your application) or you are willing to take control of the code (fork someone else's app) you can make a :ref:`hard_coded_connection`\ .
|
||||
|
||||
For 3rd-party apps or even your own apps that you don't wish to add Django-Categories as a dependency, you can configure a :ref:`lazy_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.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from django.db import models
|
||||
|
||||
class MyModel(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
category = models.ForeignKey('categories.Category')
|
||||
|
||||
Don't forget to add the field or fields to your ``ModelAdmin`` class as well.
|
||||
|
||||
|
||||
.. _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.
|
||||
|
||||
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`\ .
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
===========================================
|
||||
Django Categories v|version| documentation!
|
||||
===========================================
|
||||
|
||||
|
||||
=============================
|
||||
Django Categories v |version|
|
||||
=============================
|
||||
|
||||
Contents:
|
||||
|
||||
|
|
@ -13,7 +11,7 @@ Contents:
|
|||
getting_started
|
||||
usage
|
||||
registering_models
|
||||
templatetags
|
||||
adding_the_fields
|
||||
reference/index
|
||||
|
||||
Indices and tables
|
||||
|
|
|
|||
|
|
@ -6,4 +6,7 @@ Reference
|
|||
:maxdepth: 2
|
||||
:glob:
|
||||
|
||||
settings
|
||||
management_commands
|
||||
models
|
||||
settings
|
||||
templatetags
|
||||
|
|
|
|||
38
docs/_sources/reference/management_commands.txt
Normal file
38
docs/_sources/reference/management_commands.txt
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
.. _management-commands:
|
||||
|
||||
===================
|
||||
Management Commands
|
||||
===================
|
||||
|
||||
.. _import_categories:
|
||||
|
||||
import_categories
|
||||
=================
|
||||
|
||||
**Usage:** ``./manage.py import_categories /path/to/file.txt [/path/to/file2.txt]``
|
||||
|
||||
Imports category tree(s) from a file. Sub categories must be indented by the same multiple of spaces or tabs. The first line in the file cannot start with a space or tab and you can't mix spaces and tabs.
|
||||
|
||||
|
||||
.. _add_category_fields:
|
||||
|
||||
add_category_fields
|
||||
===================
|
||||
|
||||
**Usage:** ``./manage.py add_category_fields [app1 app2 ...]``
|
||||
|
||||
Add missing registered category fields to the database table of a specified application or all registered applications.
|
||||
|
||||
Requires Django South.
|
||||
|
||||
|
||||
.. _drop_category_field:
|
||||
|
||||
drop_category_field
|
||||
===================
|
||||
|
||||
**Usage:** ``./manage.py drop_category_field app_name model_name field_name``
|
||||
|
||||
Drop the ``field_name`` field from the ``app_name_model_name`` table, if the field is currently registered in ``CATEGORIES_SETTINGS``\ .
|
||||
|
||||
Requires Django South.
|
||||
42
docs/_sources/reference/models.txt
Normal file
42
docs/_sources/reference/models.txt
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
======
|
||||
Models
|
||||
======
|
||||
|
||||
Category
|
||||
========
|
||||
|
||||
**parent**
|
||||
The category's parent category. Leave this blank for an Category Tree.
|
||||
|
||||
**name**
|
||||
The name of the category.
|
||||
|
||||
**thumbnail**
|
||||
An optional thumbnail, that is uploaded to ``CATEGORY_SETTINGS['THUMBNAIL_UPLOAD_PATH']`` via ``CATEGORY_SETTINGS['THUMBNAIL_STORAGE']``\ .
|
||||
|
||||
**thumbnail_width**
|
||||
The thumbnail width.
|
||||
|
||||
**thumbnail_height**
|
||||
The thumbnail height.
|
||||
|
||||
**order**
|
||||
The order of this category in the listing
|
||||
|
||||
**slug**
|
||||
A slug created from the name field
|
||||
|
||||
**alternate_title**
|
||||
An alternative title to use on pages with this category.
|
||||
|
||||
**alternate_url**
|
||||
An alternative URL to use instead of the one derived from the category hierarchy.
|
||||
|
||||
**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>``
|
||||
|
|
@ -67,4 +67,11 @@ THUMBNAIL_STORAGE
|
|||
|
||||
**Default:** ``settings.DEFAULT_FILE_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
|
||||
==============
|
||||
|
||||
**Default:** ``STATIC_URL or MEDIA_URL + 'js/'``
|
||||
|
||||
**Description:** Allows for customization of javascript placement.
|
||||
146
docs/_sources/reference/templatetags.txt
Normal file
146
docs/_sources/reference/templatetags.txt
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
=============
|
||||
Template Tags
|
||||
=============
|
||||
|
||||
get_top_level_categories
|
||||
========================
|
||||
|
||||
Retrieves an alphabetical list of all the categories that have no parents.
|
||||
|
||||
Syntax:
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% get_top_level_categories as categories %}
|
||||
|
||||
Returns an list of categories ``[<category>, <category>, <category, ...]``
|
||||
|
||||
|
||||
display_path_as_ul
|
||||
==================
|
||||
|
||||
Render the category with ancestors, but no children using the ``categories/ul_tree.html`` template.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% display_path_as_ul "/Grandparent/Parent" %}
|
||||
|
||||
or
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% display_path_as_ul category_obj %}
|
||||
|
||||
Returns:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<ul>
|
||||
<li><a href="/categories/">Top</a>
|
||||
<ul>
|
||||
<li><a href="/categories/grandparent/">Grandparent</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
get_category_drilldown
|
||||
======================
|
||||
|
||||
Retrieves the specified category, its ancestors and its immediate children
|
||||
as an iterable.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% get_category_drilldown "/Grandparent/Parent" as family %}
|
||||
|
||||
or
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% get_category_drilldown category_obj as family %}
|
||||
|
||||
Sets ``family`` to::
|
||||
|
||||
[Grandparent, Parent, Child 1, Child 2, Child n]
|
||||
|
||||
|
||||
display_drilldown_as_ul
|
||||
=======================
|
||||
|
||||
Render the category with ancestors and children using the
|
||||
``categories/ul_tree.html`` template.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% display_drilldown_as_ul "/Grandparent/Parent" %}
|
||||
|
||||
or:
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% display_drilldown_as_ul category_obj %}
|
||||
|
||||
Returns:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<ul>
|
||||
<li><a href="/categories/">Top</a>
|
||||
<ul>
|
||||
<li><a href="/categories/grandparent/">Grandparent</a>
|
||||
<ul>
|
||||
<li><a href="/categories/grandparent/parent/">Parent</a>
|
||||
<ul>
|
||||
<li><a href="/categories/grandparent/parent/child1">Child1</a></li>
|
||||
<li><a href="/categories/grandparent/parent/child2">Child2</a></li>
|
||||
<li><a href="/categories/grandparent/parent/child3">Child3</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
breadcrumbs tag
|
||||
===============
|
||||
|
||||
Render breadcrumbs, using the ``categories/breadcrumbs.html`` template, using the optional ``separator`` argument.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% breadcrumbs "/Grandparent/Parent" %}
|
||||
|
||||
or:
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% breadcrumbs category_obj %}
|
||||
|
||||
Returns:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<a href="/categories/grandparent/">Grandparent</a> / Parent
|
||||
|
||||
You can alter the separator used in the template by adding a string argument to be the separator:
|
||||
|
||||
.. code-block:: django
|
||||
|
||||
{% breadcrumbs category_obj "::" %}
|
||||
|
||||
Returns:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<a href="/categories/grandparent/">Grandparent</a> :: Parent
|
||||
|
|
@ -95,6 +95,8 @@ Registering one or more Many-to-Many Category fields to a Model
|
|||
}
|
||||
}
|
||||
|
||||
.. _registering_a_m2one_relationship:
|
||||
|
||||
Registering a many-to-one relationship
|
||||
======================================
|
||||
|
||||
|
|
|
|||
125
docs/adding_the_fields.html
Normal file
125
docs/adding_the_fields.html
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
|
||||
<!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>Adding the fields to the database — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="index.html" />
|
||||
<link rel="next" title="Reference" href="reference/index.html" />
|
||||
<link rel="prev" title="Registering Models" href="registering_models.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Adding the fields to the database</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="registering_models.html" title="Registering Models" 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="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 current"><a class="current reference internal" href="">Adding the fields to the database</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#enter-south">Enter South</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#reconfiguring-fields">Reconfiguring Fields</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/adding_the_fields.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
<div id="searchbox" style="display: none">
|
||||
|
||||
<form class="search" action="search.html" method="get">
|
||||
<div class="search-wrapper">
|
||||
<span class="search-left"></span>
|
||||
<input class="prettysearch" type="text" name="q" size="18" />
|
||||
<span class="search-right"> </span>
|
||||
</div>
|
||||
<input type="submit" value="Search" class="searchbutton" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
<p class="searchtip" style="font-size: 90%">
|
||||
Enter search terms or a module, class or function name.
|
||||
</p>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body">
|
||||
|
||||
<div class="section" id="adding-the-fields-to-the-database">
|
||||
<span id="adding-the-fields"></span><h1>Adding the fields to the database<a class="headerlink" href="#adding-the-fields-to-the-database" title="Permalink to this headline">¶</a></h1>
|
||||
<p>While Django will create the appropriate columns and tables if you configure Django Categories first, many times that is not possible. You could also reset the table, but you would loose all data in it. There is another way.</p>
|
||||
<div class="section" id="enter-south">
|
||||
<h2>Enter South<a class="headerlink" href="#enter-south" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="http://south.aeracode.org/">South</a> is a Django application for managing database schema changes. South’s default behavior is for managing permanent changes to a model’s structure. In the case of dynamically adding a field or fields to a model, this doesn’t work because you are not making the change permanent. And probably don’t want to.</p>
|
||||
<p>Django Categories has a management command to create any missing fields. It requires South because it uses the South’s API for making changes to databases. The management command is simple: <tt class="docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">add_category_fields</span> <span class="pre">[app]</span></tt>. If you do not include an app name, it will attempt to do all applications configured.</p>
|
||||
<p>Running this command several times will not hurt any data or cause any errors.</p>
|
||||
</div>
|
||||
<div class="section" id="reconfiguring-fields">
|
||||
<h2>Reconfiguring Fields<a class="headerlink" href="#reconfiguring-fields" title="Permalink to this headline">¶</a></h2>
|
||||
<p>You can make changes to the field configurations as long as they do not change the underlying database structure. For example, adding a <tt class="docutils literal"><span class="pre">related_name</span></tt> (see <a class="reference internal" href="registering_models.html#registering-a-m2one-relationship"><em>Registering a many-to-one relationship</em></a>) because it only affects Django code. Changing the name of the field, however, is a different matter.</p>
|
||||
<p>Django Categories provides a complementary management command to drop a field from the database (the field must still be in the configuration to do so): <tt class="docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">drop_category_field</span> <span class="pre">app_name</span> <span class="pre">model_name</span> <span class="pre">field_name</span></tt></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>
|
||||
© Copyright 2010, CoreyOordt.
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
|
||||
</p>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div id="breadcrumbs">
|
||||
Adding the fields to the database
|
||||
</ul>
|
||||
</div>
|
||||
<script type="text/javascript" charset="utf-8" src="_static/toc.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Index — Django Categories v0.6 documentation</title>
|
||||
<title>Index — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '',
|
||||
VERSION: '0.6',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,11 +21,11 @@
|
|||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.6 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="index.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.6 documentation</p>
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Index</h1></div>
|
||||
|
|
@ -44,7 +44,7 @@
|
|||
<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="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="adding_the_fields.html">Adding the fields to the database</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Getting Started — Django Categories v0.6 documentation</title>
|
||||
<title>Getting Started — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '',
|
||||
VERSION: '0.6',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,13 +21,13 @@
|
|||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.6 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="index.html" />
|
||||
<link rel="next" title="Using categories in templates" href="usage.html" />
|
||||
<link rel="prev" title="Django Categories v|version| documentation!" href="index.html" />
|
||||
<link rel="prev" title="Django Categories v 0.7" href="index.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.6 documentation</p>
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Getting Started</h1></div>
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
<li id="page_buttons">
|
||||
<div class="headerButton"><a href="genindex.html" title="General Index" accesskey="I">index</a></div>
|
||||
<div class="headerButton"><a href="usage.html" title="Using categories in templates" accesskey="N">next</a></div>
|
||||
<div class="headerButton"><a href="index.html" title="Django Categories v|version| documentation!" accesskey="P">previous</a></div>
|
||||
<div class="headerButton"><a href="index.html" title="Django Categories v 0.7" accesskey="P">previous</a></div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -51,7 +51,7 @@
|
|||
</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="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="adding_the_fields.html">Adding the fields to the database</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
|
|
@ -121,9 +121,27 @@ Model 2
|
|||
<p>You can’t do it as both at the same time, though.</p>
|
||||
<div class="section" id="connecting-your-model-with-django-categories">
|
||||
<h2>Connecting your model with Django-Categories<a class="headerlink" href="#connecting-your-model-with-django-categories" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Because there are a few additional methods and attributes that your model needs, you can’t simply create a <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> to <tt class="docutils literal"><span class="pre">Category</span></tt>, even though that is eventually what happens.</p>
|
||||
<p>There are two ways to add Category fields to an application. If you are in control of the code (it’s your application) or you are willing to take control of the code (fork someone else’s app) you can make a <a class="reference internal" href="#hard-coded-connection"><em>Hard Coded Connection</em></a>.</p>
|
||||
<p>For 3rd-party apps or even your own apps that you don’t wish to add Django-Categories as a dependency, you can configure a <a class="reference internal" href="#lazy-connection"><em>Lazy Connection</em></a>.</p>
|
||||
<div class="section" id="hard-coded-connection">
|
||||
<span id="id1"></span><h3>Hard Coded Connection<a class="headerlink" href="#hard-coded-connection" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Hard coded connections are done in the exact same way you handle any other foreign key or many-to-many relations to a model.</p>
|
||||
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">MyModel</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
|
||||
<span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
|
||||
<span class="n">category</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="s">'categories.Category'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Don’t forget to add the field or fields to your <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> class as well.</p>
|
||||
</div>
|
||||
<div class="section" id="lazy-connection">
|
||||
<span id="id2"></span><h3>Lazy Connection<a class="headerlink" href="#lazy-connection" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Lazy connections are done through configuring Django Categories in the project’s <tt class="docutils literal"><span class="pre">settings.py</span></tt> file. When the project starts up, the configured fields are dynamically added to the configured models and admin.</p>
|
||||
<p>If you do this before you have created the database (before you ran <tt class="docutils literal"><span class="pre">manage.py</span> <span class="pre">syncdb</span></tt>), the fields will also be in the tables. If you do this after you have already created all the tables, you can run <tt class="docutils literal"><span class="pre">manage.py</span> <span class="pre">add_category_fields</span></tt> to create the fields (this requires Django South to be installed).</p>
|
||||
<p>You add a many-to-one or many-to-many relationship with Django Categories using the <tt class="docutils literal"><span class="pre">CATEGORIES_SETTINGS['FK_REGISTRY']</span></tt> and <tt class="docutils literal"><span class="pre">CATEGORIES_SETTINGS['M2M_REGISTRY']</span></tt> settings respectively. For more information see <a class="reference internal" href="registering_models.html#registering-models"><em>Registering Models</em></a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Django Categories v|version| documentation! — Django Categories v0.6 documentation</title>
|
||||
<title>Django Categories v 0.7 — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '',
|
||||
VERSION: '0.6',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,15 +21,15 @@
|
|||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.6 documentation" href="#" />
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="#" />
|
||||
<link rel="next" title="Getting Started" href="getting_started.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.6 documentation</p>
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Django Categories v|version| documentation!</h1></div>
|
||||
<div id="title"><h1>Django Categories v 0.7</h1></div>
|
||||
<ul id="headerButtons">
|
||||
<li id="toc_button"><div class="headerButton"><a href="#">Table of Contents</a></div></li>
|
||||
<li id="page_buttons">
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
<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="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="adding_the_fields.html">Adding the fields to the database</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
|
|
@ -82,8 +82,8 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body">
|
||||
|
||||
<div class="section" id="django-categories-v-version-documentation">
|
||||
<h1>Django Categories v|version| documentation!<a class="headerlink" href="#django-categories-v-version-documentation" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="section" id="django-categories-v-version">
|
||||
<h1>Django Categories v 0.7<a class="headerlink" href="#django-categories-v-version" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Contents:</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
|
|
@ -101,16 +101,16 @@
|
|||
<li class="toctree-l2"><a class="reference internal" href="registering_models.html#registering-a-many-to-many-relationship">Registering a many-to-many relationship</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="templatetags.html">Template Tags</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#get-top-level-categories">get_top_level_categories</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#display-path-as-ul">display_path_as_ul</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#get-category-drilldown">get_category_drilldown</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#display-drilldown-as-ul">display_drilldown_as_ul</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#breadcrumbs-tag">breadcrumbs tag</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="adding_the_fields.html">Adding the fields to the database</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="adding_the_fields.html#enter-south">Enter South</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="adding_the_fields.html#reconfiguring-fields">Reconfiguring Fields</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="reference/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/settings.html">Settings</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="reference/templatetags.html">Template Tags</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
@ -138,7 +138,7 @@
|
|||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div id="breadcrumbs">
|
||||
Django Categories v|version| documentation!
|
||||
Django Categories v 0.7
|
||||
</ul>
|
||||
</div>
|
||||
<script type="text/javascript" charset="utf-8" src="_static/toc.js"></script>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# Sphinx inventory version 2
|
||||
# Project: Django Categories
|
||||
# Version: 0.6
|
||||
# Version: 0.7
|
||||
# The remainder of this file is compressed using zlib.
|
||||
xÚ•<EFBFBD>K Eç®â%:E£ÃîÀ<C3AE>‰±hj¹¥D h¢»—JS?gp.çæ=tÏ¥áx<C3A1>ó¼PõŠØžîO¦S°í¼Vk:õ|P ãˆVæ‹4Ñdħ-,LƒÊÁ{i„[J9ßMyÔ3gÙ+Ó!t
|
||||
é<l¸TaL¨<4C>Î÷|êÌœ%ï2£qÅ€Vµmºecdi±2>8×y”ª½…O+ÚÁ4^ö†~±!6[ú ÿÐ^’_œy
|
||||
xÚ<EFBFBD>SËNÃ0¼û+,Ñ«Apì
q‰Jˆ~@´<>·I„‘ãJ„¯gÛÁéãnÉìÎhg=«Á@ƒ<1A>µÕŒøàåVÁ<17>ÜášôÜZåÖûÖku·á»¹Ä_R‰
®n—b‹,¾<>
Äd eUƒÇƺ±:v¨þ1iˆ¬!’†`›nðè:ÓTÚJTÂçõ¨Và"ñ>ÿ ¾› F•ÎHü^jö£È…ä•ÚO
|
||||
ù[€˜‚Ÿ‘f7kßY³ä6è}˜eðà<ÊÈQ0ÞéŸ6<C5B8>ÿÙ¼<C399>jˆô›ÛËõl2ábæíÓkÐ\±–Ñä+*w•~²+‡
|
||||
ÂlCÛõë7bR•rÿÀéåGá 6^¶±N÷Öù§×')*ˆBA„„†<E2809E>}‹WóyQž3ìœù<!œžo§? 0 “ÎögǰÚAÐ8;òЂ£3£•Ëuñ<1ñʾJ!$tÅøHM‡°=žLl¿ýð›âL«ã×
|
||||
Ö/<UÁÉ
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Reference — Django Categories v0.6 documentation</title>
|
||||
<title>Reference — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.6',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,13 +21,13 @@
|
|||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.6 documentation" href="../index.html" />
|
||||
<link rel="next" title="Settings" href="settings.html" />
|
||||
<link rel="prev" title="Template Tags" href="../templatetags.html" />
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="../index.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" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.6 documentation</p>
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Reference</h1></div>
|
||||
|
|
@ -35,8 +35,8 @@
|
|||
<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="settings.html" title="Settings" accesskey="N">next</a></div>
|
||||
<div class="headerButton"><a href="../templatetags.html" title="Template Tags" accesskey="P">previous</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>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -48,9 +48,12 @@
|
|||
<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="../templatetags.html">Template Tags</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="">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="models.html">Models</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="settings.html">Settings</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html">Template Tags</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
@ -91,6 +94,16 @@
|
|||
<h1>Reference<a class="headerlink" href="#reference" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="management_commands.html">Management Commands</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="management_commands.html#import-categories">import_categories</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="management_commands.html#add-category-fields">add_category_fields</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="management_commands.html#drop-category-field">drop_category_field</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<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#category">Category</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<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#cache-view-length">CACHE_VIEW_LENGTH</a></li>
|
||||
|
|
@ -99,6 +112,15 @@
|
|||
<li class="toctree-l2"><a class="reference internal" href="settings.html#fk-registry">FK_REGISTRY</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="settings.html#thumbnail-upload-path">THUMBNAIL_UPLOAD_PATH</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="settings.html#thumbnail-storage">THUMBNAIL_STORAGE</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="settings.html#javascript-url">JAVASCRIPT_URL</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="templatetags.html">Template Tags</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#get-top-level-categories">get_top_level_categories</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#display-path-as-ul">display_path_as_ul</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#get-category-drilldown">get_category_drilldown</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#display-drilldown-as-ul">display_drilldown_as_ul</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html#breadcrumbs-tag">breadcrumbs tag</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
|||
134
docs/reference/management_commands.html
Normal file
134
docs/reference/management_commands.html
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
|
||||
<!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>Management Commands — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="../index.html" />
|
||||
<link rel="up" title="Reference" href="index.html" />
|
||||
<link rel="next" title="Models" href="models.html" />
|
||||
<link rel="prev" title="Reference" href="index.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Management Commands</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="models.html" title="Models" accesskey="N">next</a></div>
|
||||
<div class="headerButton"><a href="index.html" title="Reference" 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="../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="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"><a class="reference internal" href="models.html">Models</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="settings.html">Settings</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html">Template Tags</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/reference/management_commands.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
<div id="searchbox" style="display: none">
|
||||
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div class="search-wrapper">
|
||||
<span class="search-left"></span>
|
||||
<input class="prettysearch" type="text" name="q" size="18" />
|
||||
<span class="search-right"> </span>
|
||||
</div>
|
||||
<input type="submit" value="Search" class="searchbutton" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
<p class="searchtip" style="font-size: 90%">
|
||||
Enter search terms or a module, class or function name.
|
||||
</p>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body">
|
||||
|
||||
<div class="section" id="management-commands">
|
||||
<span id="id1"></span><h1>Management Commands<a class="headerlink" href="#management-commands" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="section" id="import-categories">
|
||||
<span id="id2"></span><h2>import_categories<a class="headerlink" href="#import-categories" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Usage:</strong> <tt class="docutils literal"><span class="pre">./manage.py</span> <span class="pre">import_categories</span> <span class="pre">/path/to/file.txt</span> <span class="pre">[/path/to/file2.txt]</span></tt></p>
|
||||
<p>Imports category tree(s) from a file. Sub categories must be indented by the same multiple of spaces or tabs. The first line in the file cannot start with a space or tab and you can’t mix spaces and tabs.</p>
|
||||
</div>
|
||||
<div class="section" id="add-category-fields">
|
||||
<span id="id3"></span><h2>add_category_fields<a class="headerlink" href="#add-category-fields" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Usage:</strong> <tt class="docutils literal"><span class="pre">./manage.py</span> <span class="pre">add_category_fields</span> <span class="pre">[app1</span> <span class="pre">app2</span> <span class="pre">...]</span></tt></p>
|
||||
<p>Add missing registered category fields to the database table of a specified application or all registered applications.</p>
|
||||
<p>Requires Django South.</p>
|
||||
</div>
|
||||
<div class="section" id="drop-category-field">
|
||||
<span id="id4"></span><h2>drop_category_field<a class="headerlink" href="#drop-category-field" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Usage:</strong> <tt class="docutils literal"><span class="pre">./manage.py</span> <span class="pre">drop_category_field</span> <span class="pre">app_name</span> <span class="pre">model_name</span> <span class="pre">field_name</span></tt></p>
|
||||
<p>Drop the <tt class="docutils literal"><span class="pre">field_name</span></tt> field from the <tt class="docutils literal"><span class="pre">app_name_model_name</span></tt> table, if the field is currently registered in <tt class="docutils literal"><span class="pre">CATEGORIES_SETTINGS</span></tt>.</p>
|
||||
<p>Requires Django South.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>
|
||||
© Copyright 2010, CoreyOordt.
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
|
||||
</p>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div id="breadcrumbs">
|
||||
<a href="index.html" accesskey="U">Reference</a><img src="../_static/triangle_closed.png" height="9" width="9" alt=">">
|
||||
Management Commands
|
||||
</ul>
|
||||
</div>
|
||||
<script type="text/javascript" charset="utf-8" src="../_static/toc.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
146
docs/reference/models.html
Normal file
146
docs/reference/models.html
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
|
||||
<!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>Models — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="../index.html" />
|
||||
<link rel="up" title="Reference" href="index.html" />
|
||||
<link rel="next" title="Settings" href="settings.html" />
|
||||
<link rel="prev" title="Management Commands" href="management_commands.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Models</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="settings.html" title="Settings" accesskey="N">next</a></div>
|
||||
<div class="headerButton"><a href="management_commands.html" title="Management Commands" 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="../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="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 current"><a class="current reference internal" href="">Models</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="settings.html">Settings</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html">Template Tags</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/reference/models.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
<div id="searchbox" style="display: none">
|
||||
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div class="search-wrapper">
|
||||
<span class="search-left"></span>
|
||||
<input class="prettysearch" type="text" name="q" size="18" />
|
||||
<span class="search-right"> </span>
|
||||
</div>
|
||||
<input type="submit" value="Search" class="searchbutton" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
<p class="searchtip" style="font-size: 90%">
|
||||
Enter search terms or a module, class or function name.
|
||||
</p>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body">
|
||||
|
||||
<div class="section" id="models">
|
||||
<h1>Models<a class="headerlink" href="#models" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="section" id="category">
|
||||
<h2>Category<a class="headerlink" href="#category" title="Permalink to this headline">¶</a></h2>
|
||||
<dl class="docutils">
|
||||
<dt><strong>parent</strong></dt>
|
||||
<dd>The category’s parent category. Leave this blank for an Category Tree.</dd>
|
||||
<dt><strong>name</strong></dt>
|
||||
<dd>The name of the category.</dd>
|
||||
<dt><strong>thumbnail</strong></dt>
|
||||
<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>
|
||||
<dt><strong>thumbnail_width</strong></dt>
|
||||
<dd>The thumbnail width.</dd>
|
||||
<dt><strong>thumbnail_height</strong></dt>
|
||||
<dd>The thumbnail height.</dd>
|
||||
<dt><strong>order</strong></dt>
|
||||
<dd>The order of this category in the listing</dd>
|
||||
<dt><strong>slug</strong></dt>
|
||||
<dd>A slug created from the name field</dd>
|
||||
<dt><strong>alternate_title</strong></dt>
|
||||
<dd>An alternative title to use on pages with this category.</dd>
|
||||
<dt><strong>alternate_url</strong></dt>
|
||||
<dd>An alternative URL to use instead of the one derived from the category hierarchy.</dd>
|
||||
<dt><strong>description</strong></dt>
|
||||
<dd>An optional longer description of the category.</dd>
|
||||
<dt><strong>meta_keywords</strong></dt>
|
||||
<dd>Comma-separated keywords for search engines.</dd>
|
||||
<dt><strong>meta_extra</strong></dt>
|
||||
<dd>(Advanced) Any additional HTML to be placed verbatim in the <tt class="docutils literal"><span class="pre"><head></span></tt></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>
|
||||
© Copyright 2010, CoreyOordt.
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
|
||||
</p>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div id="breadcrumbs">
|
||||
<a href="index.html" accesskey="U">Reference</a><img src="../_static/triangle_closed.png" height="9" width="9" alt=">">
|
||||
Models
|
||||
</ul>
|
||||
</div>
|
||||
<script type="text/javascript" charset="utf-8" src="../_static/toc.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Settings — Django Categories v0.6 documentation</title>
|
||||
<title>Settings — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.6',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,13 +21,14 @@
|
|||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.6 documentation" href="../index.html" />
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="../index.html" />
|
||||
<link rel="up" title="Reference" href="index.html" />
|
||||
<link rel="prev" title="Reference" href="index.html" />
|
||||
<link rel="next" title="Template Tags" href="templatetags.html" />
|
||||
<link rel="prev" title="Models" href="models.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.6 documentation</p>
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Settings</h1></div>
|
||||
|
|
@ -35,7 +36,8 @@
|
|||
<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="index.html" title="Reference" accesskey="P">previous</a></div>
|
||||
<div class="headerButton"><a href="templatetags.html" title="Template Tags" accesskey="N">next</a></div>
|
||||
<div class="headerButton"><a href="models.html" title="Models" accesskey="P">previous</a></div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -47,9 +49,12 @@
|
|||
<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="../templatetags.html">Template Tags</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="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="models.html">Models</a></li>
|
||||
<li class="toctree-l2 current"><a class="current reference internal" href="">Settings</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="templatetags.html">Template Tags</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
@ -136,6 +141,11 @@
|
|||
<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>
|
||||
</div>
|
||||
<div class="section" id="javascript-url">
|
||||
<h2>JAVASCRIPT_URL<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>Description:</strong> Allows for customization of javascript placement.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
|||
219
docs/reference/templatetags.html
Normal file
219
docs/reference/templatetags.html
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
|
||||
<!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>Template Tags — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '../',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="../index.html" />
|
||||
<link rel="up" title="Reference" href="index.html" />
|
||||
<link rel="prev" title="Settings" href="settings.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Template Tags</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="settings.html" title="Settings" 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="../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="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="models.html">Models</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="settings.html">Settings</a></li>
|
||||
<li class="toctree-l2 current"><a class="current reference internal" href="">Template Tags</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>This Page</h3>
|
||||
<ul class="this-page-menu">
|
||||
<li><a href="../_sources/reference/templatetags.txt"
|
||||
rel="nofollow">Show Source</a></li>
|
||||
</ul>
|
||||
<div id="searchbox" style="display: none">
|
||||
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<div class="search-wrapper">
|
||||
<span class="search-left"></span>
|
||||
<input class="prettysearch" type="text" name="q" size="18" />
|
||||
<span class="search-right"> </span>
|
||||
</div>
|
||||
<input type="submit" value="Search" class="searchbutton" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
<p class="searchtip" style="font-size: 90%">
|
||||
Enter search terms or a module, class or function name.
|
||||
</p>
|
||||
</div>
|
||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body">
|
||||
|
||||
<div class="section" id="template-tags">
|
||||
<h1>Template Tags<a class="headerlink" href="#template-tags" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="section" id="get-top-level-categories">
|
||||
<h2>get_top_level_categories<a class="headerlink" href="#get-top-level-categories" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Retrieves an alphabetical list of all the categories that have no parents.</p>
|
||||
<p>Syntax:</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">get_top_level_categories</span> <span class="k">as</span> <span class="nv">categories</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Returns an list of categories <tt class="docutils literal"><span class="pre">[<category>,</span> <span class="pre"><category>,</span> <span class="pre"><category,</span> <span class="pre">...]</span></tt></p>
|
||||
</div>
|
||||
<div class="section" id="display-path-as-ul">
|
||||
<h2>display_path_as_ul<a class="headerlink" href="#display-path-as-ul" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Render the category with ancestors, but no children using the <tt class="docutils literal"><span class="pre">categories/ul_tree.html</span></tt> template.</p>
|
||||
<p>Example:</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">display_path_as_ul</span> <span class="s2">"/Grandparent/Parent"</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>or</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">display_path_as_ul</span> <span class="nv">category_obj</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Returns:</p>
|
||||
<div class="highlight-html"><div class="highlight"><pre><span class="nt"><ul></span>
|
||||
<span class="nt"><li><a</span> <span class="na">href=</span><span class="s">"/categories/"</span><span class="nt">></span>Top<span class="nt"></a></span>
|
||||
<span class="nt"><ul></span>
|
||||
<span class="nt"><li><a</span> <span class="na">href=</span><span class="s">"/categories/grandparent/"</span><span class="nt">></span>Grandparent<span class="nt"></a></li></span>
|
||||
<span class="nt"></ul></span>
|
||||
<span class="nt"></li></span>
|
||||
<span class="nt"></ul></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="get-category-drilldown">
|
||||
<h2>get_category_drilldown<a class="headerlink" href="#get-category-drilldown" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Retrieves the specified category, its ancestors and its immediate children
|
||||
as an iterable.</p>
|
||||
<p>Example:</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">get_category_drilldown</span> <span class="s2">"/Grandparent/Parent"</span> <span class="k">as</span> <span class="nv">family</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>or</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">get_category_drilldown</span> <span class="nv">category_obj</span> <span class="k">as</span> <span class="nv">family</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Sets <tt class="docutils literal"><span class="pre">family</span></tt> to:</p>
|
||||
<div class="highlight-python"><pre>[Grandparent, Parent, Child 1, Child 2, Child n]</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="display-drilldown-as-ul">
|
||||
<h2>display_drilldown_as_ul<a class="headerlink" href="#display-drilldown-as-ul" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Render the category with ancestors and children using the
|
||||
<tt class="docutils literal"><span class="pre">categories/ul_tree.html</span></tt> template.</p>
|
||||
<p>Example:</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">display_drilldown_as_ul</span> <span class="s2">"/Grandparent/Parent"</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>or:</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">display_drilldown_as_ul</span> <span class="nv">category_obj</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Returns:</p>
|
||||
<div class="highlight-html"><div class="highlight"><pre><span class="nt"><ul></span>
|
||||
<span class="nt"><li><a</span> <span class="na">href=</span><span class="s">"/categories/"</span><span class="nt">></span>Top<span class="nt"></a></span>
|
||||
<span class="nt"><ul></span>
|
||||
<span class="nt"><li><a</span> <span class="na">href=</span><span class="s">"/categories/grandparent/"</span><span class="nt">></span>Grandparent<span class="nt"></a></span>
|
||||
<span class="nt"><ul></span>
|
||||
<span class="nt"><li><a</span> <span class="na">href=</span><span class="s">"/categories/grandparent/parent/"</span><span class="nt">></span>Parent<span class="nt"></a></span>
|
||||
<span class="nt"><ul></span>
|
||||
<span class="nt"><li><a</span> <span class="na">href=</span><span class="s">"/categories/grandparent/parent/child1"</span><span class="nt">></span>Child1<span class="nt"></a></li></span>
|
||||
<span class="nt"><li><a</span> <span class="na">href=</span><span class="s">"/categories/grandparent/parent/child2"</span><span class="nt">></span>Child2<span class="nt"></a></li></span>
|
||||
<span class="nt"><li><a</span> <span class="na">href=</span><span class="s">"/categories/grandparent/parent/child3"</span><span class="nt">></span>Child3<span class="nt"></a></li></span>
|
||||
<span class="nt"></ul></span>
|
||||
<span class="nt"></li></span>
|
||||
<span class="nt"></ul></span>
|
||||
<span class="nt"></li></span>
|
||||
<span class="nt"></ul></span>
|
||||
<span class="nt"></li></span>
|
||||
<span class="nt"></ul></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="breadcrumbs-tag">
|
||||
<h2>breadcrumbs tag<a class="headerlink" href="#breadcrumbs-tag" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Render breadcrumbs, using the <tt class="docutils literal"><span class="pre">categories/breadcrumbs.html</span></tt> template, using the optional <tt class="docutils literal"><span class="pre">separator</span></tt> argument.</p>
|
||||
<p>Example:</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">breadcrumbs</span> <span class="s2">"/Grandparent/Parent"</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>or:</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">breadcrumbs</span> <span class="nv">category_obj</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Returns:</p>
|
||||
<div class="highlight-html"><div class="highlight"><pre><span class="nt"><a</span> <span class="na">href=</span><span class="s">"/categories/grandparent/"</span><span class="nt">></span>Grandparent<span class="nt"></a></span> / Parent
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>You can alter the separator used in the template by adding a string argument to be the separator:</p>
|
||||
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">breadcrumbs</span> <span class="nv">category_obj</span> <span class="s2">"::"</span> <span class="cp">%}</span><span class="x"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Returns:</p>
|
||||
<div class="highlight-html"><div class="highlight"><pre><span class="nt"><a</span> <span class="na">href=</span><span class="s">"/categories/grandparent/"</span><span class="nt">></span>Grandparent<span class="nt"></a></span> :: Parent
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>
|
||||
© Copyright 2010, CoreyOordt.
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
|
||||
</p>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div id="breadcrumbs">
|
||||
<a href="index.html" accesskey="U">Reference</a><img src="../_static/triangle_closed.png" height="9" width="9" alt=">">
|
||||
Template Tags
|
||||
</ul>
|
||||
</div>
|
||||
<script type="text/javascript" charset="utf-8" src="../_static/toc.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Registering Models — Django Categories v0.6 documentation</title>
|
||||
<title>Registering Models — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '',
|
||||
VERSION: '0.6',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,13 +21,13 @@
|
|||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.6 documentation" href="index.html" />
|
||||
<link rel="next" title="Template Tags" href="templatetags.html" />
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="index.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" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.6 documentation</p>
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Registering Models</h1></div>
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
<li id="toc_button"><div class="headerButton"><a href="#">Table of Contents</a></div></li>
|
||||
<li id="page_buttons">
|
||||
<div class="headerButton"><a href="genindex.html" title="General Index" accesskey="I">index</a></div>
|
||||
<div class="headerButton"><a href="templatetags.html" title="Template Tags" accesskey="N">next</a></div>
|
||||
<div class="headerButton"><a href="adding_the_fields.html" title="Adding the fields to the database" accesskey="N">next</a></div>
|
||||
<div class="headerButton"><a href="usage.html" title="Using categories in templates" accesskey="P">previous</a></div>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
<li class="toctree-l2"><a class="reference internal" href="#registering-a-many-to-many-relationship">Registering a many-to-many relationship</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="adding_the_fields.html">Adding the fields to the database</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
|
|
@ -164,7 +164,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="section" id="registering-a-many-to-one-relationship">
|
||||
<h2>Registering a many-to-one relationship<a class="headerlink" href="#registering-a-many-to-one-relationship" title="Permalink to this headline">¶</a></h2>
|
||||
<span id="registering-a-m2one-relationship"></span><h2>Registering a many-to-one relationship<a class="headerlink" href="#registering-a-many-to-one-relationship" title="Permalink to this headline">¶</a></h2>
|
||||
<p>To create a many-to-one relationship (foreign key) between a model and Django Categories, you register your model with the <tt class="docutils literal"><span class="pre">register_fk</span></tt> function.</p>
|
||||
<dl class="function">
|
||||
<dt id="register_fk">
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Search — Django Categories v0.6 documentation</title>
|
||||
<title>Search — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '',
|
||||
VERSION: '0.6',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<script type="text/javascript" src="_static/searchtools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.6 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="index.html" />
|
||||
<script type="text/javascript">
|
||||
jQuery(function() { Search.loadIndex("searchindex.js"); });
|
||||
</script>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.6 documentation</p>
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Search</h1></div>
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
<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="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="adding_the_fields.html">Adding the fields to the database</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Template Tags — Django Categories v0.6 documentation</title>
|
||||
<title>Template Tags — Django Categories v0.7beta1 documentation</title>
|
||||
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '',
|
||||
VERSION: '0.6',
|
||||
VERSION: '0.7beta1',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,13 +21,13 @@
|
|||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.6 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.7beta1 documentation" href="index.html" />
|
||||
<link rel="next" title="Reference" href="reference/index.html" />
|
||||
<link rel="prev" title="Registering Models" href="registering_models.html" />
|
||||
<link rel="prev" title="Adding the fields to the database" href="adding_the_fields.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.6 documentation</p>
|
||||
<p>Django Categories v0.7beta1 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Template Tags</h1></div>
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
<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="registering_models.html" title="Registering Models" accesskey="P">previous</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>
|
||||
|
|
@ -48,6 +48,7 @@
|
|||
<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="">Template Tags</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#get-top-level-categories">get_top_level_categories</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#display-path-as-ul">display_path_as_ul</a></li>
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>Using categories in templates — Django Categories v0.6 documentation</title>
|
||||
<title>Using categories in templates — Django Categories v0.7 documentation</title>
|
||||
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: '',
|
||||
VERSION: '0.6',
|
||||
VERSION: '0.7',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true
|
||||
|
|
@ -21,13 +21,13 @@
|
|||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<link rel="top" title="Django Categories v0.6 documentation" href="index.html" />
|
||||
<link rel="top" title="Django Categories v0.7 documentation" href="index.html" />
|
||||
<link rel="next" title="Registering Models" href="registering_models.html" />
|
||||
<link rel="prev" title="Getting Started" href="getting_started.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="docstitle">
|
||||
<p>Django Categories v0.6 documentation</p>
|
||||
<p>Django Categories v0.7 documentation</p>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="title"><h1>Using categories in templates</h1></div>
|
||||
|
|
@ -51,7 +51,7 @@
|
|||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="registering_models.html">Registering Models</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="templatetags.html">Template Tags</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="adding_the_fields.html">Adding the fields to the database</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@
|
|||
<script type="text/javascript">
|
||||
(function($) {
|
||||
$(document).ready(function() {
|
||||
treeTable = $("#result_list").treeTable({initialState : "{{ EDITOR_TREE_INITIAL_STATE }}"});
|
||||
var srchString = document.getElementById('searchbar').value;
|
||||
if (srchString == '')
|
||||
treeTable = $("#result_list").treeTable({initialState : "{{ EDITOR_TREE_INITIAL_STATE }}"});
|
||||
else
|
||||
treeTable = $("#result_list").treeTable({initialState : "expanded"});
|
||||
function toggleChildren(index, value) {
|
||||
var row = value.parentNode.parentNode;
|
||||
if (row.className.match(/child-of-node-\d+/)) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
from django.db import models
|
||||
from django.template import Library
|
||||
from django.contrib.admin.templatetags.admin_list import result_headers
|
||||
from django.contrib.admin.util import lookup_field, display_for_field, label_for_field
|
||||
try:
|
||||
from django.contrib.admin.util import lookup_field, display_for_field, label_for_field
|
||||
except ImportError:
|
||||
from editor.utils import lookup_field, display_for_field, label_for_field
|
||||
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.utils.encoding import smart_unicode, force_unicode
|
||||
|
|
|
|||
103
editor/utils.py
Normal file
103
editor/utils.py
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
"""
|
||||
Provides compatibility with Django 1.1
|
||||
|
||||
Copied from django.contrib.admin.util
|
||||
"""
|
||||
from django.db import models
|
||||
from django.utils.encoding import force_unicode, smart_unicode, smart_str
|
||||
|
||||
def lookup_field(name, obj, model_admin=None):
|
||||
opts = obj._meta
|
||||
try:
|
||||
f = opts.get_field(name)
|
||||
except models.FieldDoesNotExist:
|
||||
# For non-field values, the value is either a method, property or
|
||||
# returned via a callable.
|
||||
if callable(name):
|
||||
attr = name
|
||||
value = attr(obj)
|
||||
elif (model_admin is not None and hasattr(model_admin, name) and
|
||||
not name == '__str__' and not name == '__unicode__'):
|
||||
attr = getattr(model_admin, name)
|
||||
value = attr(obj)
|
||||
else:
|
||||
attr = getattr(obj, name)
|
||||
if callable(attr):
|
||||
value = attr()
|
||||
else:
|
||||
value = attr
|
||||
f = None
|
||||
else:
|
||||
attr = None
|
||||
value = getattr(obj, name)
|
||||
return f, attr, value
|
||||
|
||||
|
||||
def label_for_field(name, model, model_admin=None, return_attr=False):
|
||||
"""
|
||||
Returns a sensible label for a field name. The name can be a callable or the
|
||||
name of an object attributes, as well as a genuine fields. If return_attr is
|
||||
True, the resolved attribute (which could be a callable) is also returned.
|
||||
This will be None if (and only if) the name refers to a field.
|
||||
"""
|
||||
attr = None
|
||||
try:
|
||||
field = model._meta.get_field_by_name(name)[0]
|
||||
if isinstance(field, RelatedObject):
|
||||
label = field.opts.verbose_name
|
||||
else:
|
||||
label = field.verbose_name
|
||||
except models.FieldDoesNotExist:
|
||||
if name == "__unicode__":
|
||||
label = force_unicode(model._meta.verbose_name)
|
||||
attr = unicode
|
||||
elif name == "__str__":
|
||||
label = smart_str(model._meta.verbose_name)
|
||||
attr = str
|
||||
else:
|
||||
if callable(name):
|
||||
attr = name
|
||||
elif model_admin is not None and hasattr(model_admin, name):
|
||||
attr = getattr(model_admin, name)
|
||||
elif hasattr(model, name):
|
||||
attr = getattr(model, name)
|
||||
else:
|
||||
message = "Unable to lookup '%s' on %s" % (name, model._meta.object_name)
|
||||
if model_admin:
|
||||
message += " or %s" % (model_admin.__class__.__name__,)
|
||||
raise AttributeError(message)
|
||||
|
||||
if hasattr(attr, "short_description"):
|
||||
label = attr.short_description
|
||||
elif callable(attr):
|
||||
if attr.__name__ == "<lambda>":
|
||||
label = "--"
|
||||
else:
|
||||
label = pretty_name(attr.__name__)
|
||||
else:
|
||||
label = pretty_name(name)
|
||||
if return_attr:
|
||||
return (label, attr)
|
||||
else:
|
||||
return label
|
||||
|
||||
def display_for_field(value, field):
|
||||
from django.contrib.admin.templatetags.admin_list import _boolean_icon
|
||||
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
|
||||
|
||||
if field.flatchoices:
|
||||
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
|
||||
# NullBooleanField needs special-case null-handling, so it comes
|
||||
# before the general null test.
|
||||
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
|
||||
return _boolean_icon(value)
|
||||
elif value is None:
|
||||
return EMPTY_CHANGELIST_VALUE
|
||||
elif isinstance(field, models.DateField) or isinstance(field, models.TimeField):
|
||||
return formats.localize(value)
|
||||
elif isinstance(field, models.DecimalField):
|
||||
return formats.number_format(value, field.decimal_places)
|
||||
elif isinstance(field, models.FloatField):
|
||||
return formats.number_format(value)
|
||||
else:
|
||||
return smart_unicode(value)
|
||||
Loading…
Reference in a new issue