mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Merge branch 'master' of http://opensource.washingtontimes.com/git/public/django-categories
This commit is contained in:
commit
f6db9f2006
5 changed files with 24 additions and 16 deletions
|
|
@ -31,5 +31,5 @@ class Category(models.Model):
|
|||
def __unicode__(self):
|
||||
ancestors = self.get_ancestors()
|
||||
return ' > '.join([force_unicode(i.name) for i in ancestors]+[self.name,])
|
||||
|
||||
|
||||
mptt.register(Category, order_insertion_by=['name'])
|
||||
|
|
|
|||
4
categories/templates/categories/category_detail.html
Normal file
4
categories/templates/categories/category_detail.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<h2>{{ category }}</h2>
|
||||
{% if category.parent %}<h3>Go up to <a href="{{ category.parent.get_absolute_url }}">{{ category.parent }}</a></h3>{% endif %}
|
||||
<p>{{ category.description }}</p>
|
||||
{% if category.children.count %}<h3>Subcategories</h3><ul>{% for child in category.children.all %}<li><a href="{{ child.get_absolute_url }}">{{ child }}</a></li>{% endfor %}</ul>{% endif %}
|
||||
2
categories/templates/categories/category_list.html
Normal file
2
categories/templates/categories/category_list.html
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<h2>Categories</h2>
|
||||
<ul>{% for category in object_list %}<li><a href="{{ category.get_absolute_url }}">{{ category }}</a></li>{% endfor %}</ul>
|
||||
|
|
@ -2,7 +2,7 @@ from django.conf.urls.defaults import *
|
|||
from categories.models import Category
|
||||
|
||||
categorytree_dict = {
|
||||
'queryset': Category.objects.all()
|
||||
'queryset': Category.objects.filter(level=0)
|
||||
}
|
||||
|
||||
urlpatterns = patterns('django.views.generic.list_detail',
|
||||
|
|
|
|||
|
|
@ -1,22 +1,24 @@
|
|||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.template import RequestContext
|
||||
from categories.models import Category
|
||||
from django.http import HttpResponse
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template.loader import select_template
|
||||
from categories.models import Category
|
||||
|
||||
@cache_page(3600)
|
||||
def category_detail(request, path, with_stories=False,
|
||||
template_name='categories/category_detail.html'):
|
||||
|
||||
path_items = path.strip('/').split('/')
|
||||
slug = path_items[-1]
|
||||
level = len(path_items)
|
||||
context = {}
|
||||
category = get_object_or_404(Category,
|
||||
slug__iexact=slug, level=level-1)
|
||||
|
||||
context['category'] = category
|
||||
|
||||
return render_to_response(template_name,
|
||||
context,
|
||||
context_instance=RequestContext(request)
|
||||
)
|
||||
slug__iexact = path_items[-1],
|
||||
level = len(path_items)-1)
|
||||
|
||||
templates = []
|
||||
while path_items:
|
||||
templates.append('categories/%s.html' % '_'.join(path_items))
|
||||
path_items.pop()
|
||||
templates.append(template_name)
|
||||
|
||||
context = RequestContext(request)
|
||||
context.update({'category':category})
|
||||
return HttpResponse(select_template(templates).render(context))
|
||||
Loading…
Reference in a new issue