views:

293

answers:

1

I'm using the django app django-tagging and I'm trying to filter out certain tags for a simple tag search.

the variable 'tag' is text of some tag I am searching for. 'Widget' is the model associated with the tags.

tags = Tag.objects.usage_for_model(Widget, counts=True, filters=dict(tags__icontains=tag))

The code above sort of works. It returns a list of tags which contain the tag, but it also returns other tags associated with widgets that use that tag.

For example, I have a widget: A, and A has tags: django, python, mysql. If I do a simple search for 'django':

tags = Tag.objects.usage_for_model(Widget, counts=True, filters=dict(tags__icontains='django'))

tags will return this list: [(Tag: django), (Tag: python), (Tag: mysql)]

I only want it to return: [(Tag: django)]

How do I do this?

A: 

Better late than never?

djangoTag = Tag.objects.get(name='django')
djangoWidgets = TaggedItem.objects.get_union_by_model(Widget, djangoTag)
John Mee