How to get all the (unique) tags from django-taggit? I would like to display all the tags in a side bar. Currently I am able to get all the tags for a particular post, but now I need to get all the unique tags in the entire blog.
code in models.py:
from django.db import models
from taggit.managers import TaggableManager
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()
created = models.DateTimeField()
tags = TaggableManager()
You can use all()
to get all the tags in your database:
from taggit.models import Tag
tags = Tag.objects.all()
If you need a complete solution, have a look at django-taggit-templatetags
. It provides several templatetags, including one for tag list, to expose various taggit APIs directly to templates.
The currently maintained fork supporting newer versions of django is: https://github.com/fizista/django-taggit-templatetags2
django-taggit-templatetags has not been maintained for some years.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With