0

Say I have 4 different content types - photo, blog, story and drawings. Each of these content types is attached to a taggable manager.

Tags = TaggableManager(blank=True, through=CustomTag)

Now, say I tag each model with 'test_tag', id=1

How can I get a list of all the objects which have been tagged 'test_tag' without querying each type individually like this:

#tag = 1
MyContentType.objects.filter(tags__id__in=tag)

I looked into trying to get these using ContentType and filtering by model and tag id but it seems a really roundabout way of doing things and I'm sure there must be a better way.

So, is there a simple way to get all objects which share the same tag?

Anto
  • 6,806
  • 8
  • 43
  • 65
rix
  • 10,104
  • 14
  • 65
  • 92

1 Answers1

0

Figured it out eventually, hope this helps someone...

tag_obj = get_object_or_404(Tag, pk=tag)
tagged = TaggedItem.objects.filter(tag=tag_obj)
rix
  • 10,104
  • 14
  • 65
  • 92