Commit 76c8a84f by Alex Gaynor

more tests, added a remove method to taggable manager

parent dba4d502
...@@ -40,6 +40,14 @@ class _TaggableManager(models.Manager): ...@@ -40,6 +40,14 @@ class _TaggableManager(models.Manager):
self.add(tags) self.add(tags)
@require_instance_manager @require_instance_manager
def remove(self, tags):
if isinstance(tags, basestring):
tags = [tags]
TaggedItem.objects.filter(object_id=self.object_id,
content_type=ContentType.objects.get_for_model(self.model)).filter(
tag__name__in=tags).delete()
@require_instance_manager
def clear(self): def clear(self):
TaggedItem.objects.filter(object_id=self.object_id, TaggedItem.objects.filter(object_id=self.object_id,
content_type=ContentType.objects.get_for_model(self.model)).delete() content_type=ContentType.objects.get_for_model(self.model)).delete()
...@@ -22,3 +22,11 @@ class AddTagTestCase(BaseTaggingTest): ...@@ -22,3 +22,11 @@ class AddTagTestCase(BaseTaggingTest):
pair.tags.add('green') pair.tags.add('green')
self.assert_tags_equal(pair.tags.all(), ['green']) self.assert_tags_equal(pair.tags.all(), ['green'])
self.assert_tags_equal(Food.tags.all(), ['green']) self.assert_tags_equal(Food.tags.all(), ['green'])
apple.tags.add('red')
self.assert_tags_equal(apple.tags.all(), ['green', 'red'])
self.assert_tags_equal(Food.tags.all(), ['green', 'red'])
apple.tags.remove('green')
self.assert_tags_equal(apple.tags.all(), ['red'])
self.assert_tags_equal(Food.tags.all(), ['green', 'red'])
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