diff options
author | luxagraf <sng@luxagraf.net> | 2012-09-22 22:27:04 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2012-09-22 22:27:04 -0400 |
commit | efb623af0bcb47d510501c282e1326b11343a29c (patch) | |
tree | 3a35fb19f5eba3b219c65277a5fb712cbe9604ac /app/lib/taggit/views.py | |
parent | 0b481fd7931c2ae20ca21f89a87f2ba6a6c01e10 (diff) |
site reorg
Diffstat (limited to 'app/lib/taggit/views.py')
-rw-r--r-- | app/lib/taggit/views.py | 18 |
1 files changed, 18 insertions, 0 deletions
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) |