Skip to content

Instantly share code, notes, and snippets.

@pije76
Forked from macndesign/base.html
Created June 16, 2013 09:40
Show Gist options
  • Save pije76/5791548 to your computer and use it in GitHub Desktop.
Save pije76/5791548 to your computer and use it in GitHub Desktop.
{% load core_utils %}
<ul id="tags" class="nav nav-tabs nav-stacked">
{% for tag in tags %}
{% if tag_full_list|list_count:tag %}
<li>
<a href="{% url "post:posts-tagged-related" tag.slug %}">
{{ tag.name }} <span class="label label-info">{{ tag_full_list|list_count:tag }}</span>
</a>
</li>
{% endif %}
{% endfor %}
</ul>
# coding: utf-8
from taggit.models import Tag
from core.models import Post
def active_post_tags(request):
# Lista tags referentes aos posts ativos
posts = Post.objects.ativos()
active_tags = [post.tags.all() for post in posts]
tag_full_list = [t for tag in active_tags for t in tag]
all_tags = Tag.objects.all()
tags = [tag for tag in all_tags if tag_full_list.count(tag)]
return {'tags': tags, 'tag_full_list': tag_full_list}
from django import template
register = template.Library()
@register.filter
def list_count(value, arg):
return value.count(arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment