azio
azio

Reputation: 585

Getting a specific tag object using django-taggit

I am using django-taggit to manage the tags in my app. I am able to pull the tagged items like this:

photos = Photo.objects.filter(
    Q(status = 1) & Q(tags__id__in=[id])
).order_by('-position')

What I want to get is the current tag name. How can I do that?

Upvotes: 0

Views: 616

Answers (1)

Aamir Rind
Aamir Rind

Reputation: 39649

You are passing tags__id__in which means you know the tag ids?. So just get them directly.

tags = Tags.objects.filter(id__in=[ids])
for tag in tags:
    print tag.name

Alternately using your mentioned query (I am excluding tags__id__in from your query)

photos = Photo.objects.filter(status=1).order_by('-position')
for photo in photos:
    tags = photo.tags.all()
    for tag in tags:
        print tag.name

Upvotes: 2

Related Questions