From efb623af0bcb47d510501c282e1326b11343a29c Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sat, 22 Sep 2012 22:27:04 -0400 Subject: site reorg --- app/lib/taggit/views.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/lib/taggit/views.py (limited to 'app/lib/taggit/views.py') diff --git a/app/lib/taggit/views.py b/app/lib/taggit/views.py new file mode 100644 index 0000000..68e955b --- /dev/null +++ b/app/lib/taggit/views.py @@ -0,0 +1,18 @@ +from django.contrib.contenttypes.models import ContentType +from django.shortcuts import get_object_or_404 +from django.views.generic.list_detail import object_list + +from taggit.models import TaggedItem, Tag + + +def tagged_object_list(request, slug, queryset, **kwargs): + if callable(queryset): + queryset = queryset() + tag = get_object_or_404(Tag, slug=slug) + qs = queryset.filter(pk__in=TaggedItem.objects.filter( + tag=tag, content_type=ContentType.objects.get_for_model(queryset.model) + ).values_list("object_id", flat=True)) + if "extra_context" not in kwargs: + kwargs["extra_context"] = {} + kwargs["extra_context"]["tag"] = tag + return object_list(request, qs, **kwargs) -- cgit v1.2.3-70-g09d2