Permalink
Browse files

added post_count to blog_categories tag

  • Loading branch information...
1 parent 2f65bdf commit cec9913d2cedd63094e12dc370d4ebcffaf8f48e @fusepilot fusepilot committed Jul 3, 2011
View
BIN .DS_Store
Binary file not shown.
@@ -31,7 +31,7 @@ <h3>{% trans "Categories" %}</h3>
<ul>
{% for category in categories %}
<li><a href="{% url blog_post_list_category category.slug %}"
- >{{ category }}</a></li>
+ >{{ category }}</a> ({{ category.post_count }})</li>
{% endfor %}
</ul>
{% endif %}
@@ -34,7 +34,8 @@ def blog_categories(*args):
Put a list of categories for blog posts into the template context.
"""
posts = BlogPost.objects.published()
- return list(BlogCategory.objects.filter(blogposts__in=posts).distinct())
+ categories = BlogCategory.objects.filter(blogposts__in=posts)
+ return list(categories.annotate(post_count=Count("blogposts")))
@register.as_tag

0 comments on commit cec9913

Please sign in to comment.