Commit 56e1227f by Rob Hudson

Merge remote branch 'alex/master'

parents aa961dd9 345554b9
...@@ -22,7 +22,7 @@ Then you can use the API like so: ...@@ -22,7 +22,7 @@ Then you can use the API like so:
[<Tag: red>, <Tag: green>, <Tag: delicious>] [<Tag: red>, <Tag: green>, <Tag: delicious>]
>>> apple.tags.remove("green") >>> apple.tags.remove("green")
[<Tag: red>, <Tag: delicious>] [<Tag: red>, <Tag: delicious>]
>>> Food.objects.filter(tags="red") >>> Food.objects.filter(tags__in=["red"])
[<Food: apple>, <Food: cherry>] [<Food: apple>, <Food: cherry>]
......
...@@ -48,10 +48,8 @@ class TaggableManager(object): ...@@ -48,10 +48,8 @@ class TaggableManager(object):
getattr(instance, self.name).set(*value) getattr(instance, self.name).set(*value)
def get_db_prep_lookup(self, lookup_type, value): def get_db_prep_lookup(self, lookup_type, value):
if lookup_type not in ("in", "exact"): if lookup_type != "in":
raise ValueError("You can't do lookups other than \"in\" and \"exact\" on Tags") raise ValueError("You can't do lookups other than \"in\" on Tags")
if lookup_type == "exact":
value = [value]
if all(isinstance(v, Tag) for v in value): if all(isinstance(v, Tag) for v in value):
qs = TaggedItem.objects.filter(tag__in=value) qs = TaggedItem.objects.filter(tag__in=value)
elif all(isinstance(v, basestring) for v in value): elif all(isinstance(v, basestring) for v in value):
......
...@@ -59,10 +59,8 @@ class LookupByTagTestCase(BaseTaggingTest): ...@@ -59,10 +59,8 @@ class LookupByTagTestCase(BaseTaggingTest):
dog.tags.add("woof", "red") dog.tags.add("woof", "red")
self.assertEqual(list(Food.objects.filter(tags__in=["red"]).distinct()), [apple]) self.assertEqual(list(Food.objects.filter(tags__in=["red"]).distinct()), [apple])
self.assertEqual(list(Food.objects.filter(tags="red").distinct()), [apple])
tag = Tag.objects.get(name="woof") tag = Tag.objects.get(name="woof")
self.assertEqual(list(Pet.objects.filter(tags=tag)), [dog]) self.assertEqual(list(Pet.objects.filter(tags__in=[tag])), [dog])
class TaggableFormTestCase(BaseTaggingTest): class TaggableFormTestCase(BaseTaggingTest):
......
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