To show all the tags in a database a Tag[List](/blog/611/) with a generic ListView can be created and for showing the content from an app with a specific tag the queryset of another ListView can be overwritten: ::
# data/urls.py
...
from views import Tag[List](/blog/611/), Tagged[List](/blog/611/)
...
url(r'data/tags/$', Taglist.as_view()),
url(r'data/tag/(?P\w+)/$', Tagged[List](/blog/611/).as_view()),
...
# views.py
...
from data.models import Entry
from taggit.models import Tag, TaggedItem
...
class Tag[List](/blog/611/)(ListView):
"""Get all the tags in the db."""
queryset = Tag.objects.all()
template_name = 'data/tag_list.html'
paginate_by = 10
class Tagged[List](/blog/611/)(ListView):
"""Get all the content for a tag."""
template_name = "data/tagged_list.html"
def get_queryset(self):
#return TaggedItem.objects.filter(tag__iexact=self.kwargs['tag']) # If interested in all tagged models.
return Entry.objects.filter(tags__name__in=[self.kwargs['tag']]) # If only interested in tagged entries.
...
# data/tagged_list.html
...
{% for item in TaggedItem_list %}
{{ item.content_objects }}
{% endfor %}
...