Commit ab8b54f4 by Matt Croydon Committed by Alex Gaynor

Only create one TaggedItem if the same tag is given more than once, with a test…

Only create one TaggedItem if the same tag is given more than once, with a test showing the problem.  Fixes issue #8 (http://github.com/alex/django-taggit/issues#issue/8) by applying Charlie's patch.
parent 993f9717
......@@ -127,7 +127,7 @@ class _TaggableManager(models.Manager):
for tag in tags:
if not isinstance(tag, Tag):
tag, _ = Tag.objects.get_or_create(name=tag)
TaggedItem.objects.create(object_id=self.object_id,
TaggedItem.objects.get_or_create(object_id=self.object_id,
content_type=ContentType.objects.get_for_model(self.model), tag=tag)
@require_instance_manager
......
from taggit.tests.tests import AddTagTestCase, LookupByTagTestCase, TaggableFormTestCase, SimilarityByTagTestCase
from taggit.tests.tests import AddTagTestCase, LookupByTagTestCase, TaggableFormTestCase, SimilarityByTagTestCase, TagReuseTestCase
......@@ -104,3 +104,9 @@ class SimilarityByTagTestCase(BaseTaggingTest):
similar_objs = apple.tags.similar_objects()
self.assertEqual(similar_objs, [pear, watermelon])
self.assertEqual(map(lambda x: x.similar_tags, similar_objs), [3, 2])
class TagReuseTestCase(BaseTaggingTest):
def test_tag_reuse(self):
apple = Food.objects.create(name="apple")
apple.tags.add("juicy", "juicy")
self.assert_tags_equal(apple.tags.all(), ['juicy'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment