Created
November 4, 2010 01:45
-
-
Save arlolra/662018 to your computer and use it in GitHub Desktop.
basic.blog tag view
This file contains 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
def tag_detail(request, slug, template_name = 'blog/tag_detail.html', **kwargs): | |
""" | |
Tag detail | |
Template: ``blog/tag_detail.html`` | |
Context: | |
object_list | |
List of posts specific to the given tag. | |
tag | |
Given tag. | |
""" | |
#tag = get_object_or_404(Tag, name__iexact=slug) | |
# i changed this | |
from django.template.defaultfilters import slugify | |
from django.http import Http404 | |
postags = Tag.objects.usage_for_model(Post) | |
tags = [] | |
for pt in postags: | |
if slugify(pt.name) == slugify(slug): | |
tags.append(pt) | |
if not tags: | |
raise Http404 | |
return list_detail.object_list( | |
request, | |
queryset = TaggedItem.objects.get_union_by_model(Post, tags).filter(status=2), | |
extra_context = {'tag': tags[0]}, | |
template_name = template_name, | |
**kwargs | |
) | |
# endichanged |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment