-
-
Save pije76/5791548 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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