Commit 90fe33b7 by Alex Gaynor

Allow __exact lookups

parent f64167b8
......@@ -44,8 +44,10 @@ class TaggableManager(object):
pass
def get_db_prep_lookup(self, lookup_type, value):
if lookup_type != "in":
raise ValueError("You can't do lookups other than in on Tags")
if lookup_type not in ("in", "exact"):
raise ValueError("You can't do lookups other than \"in\" and \"exact\" on Tags")
if lookup_type == "exact":
value = [value]
qs = TaggedItem.objects.filter(tag__name__in=value).values_list("pk", flat=True)
sql, params = qs.query.as_sql()
return QueryWrapper(("(%s)" % sql), params)
......
......@@ -53,6 +53,8 @@ class LookupByTagTestCase(BaseTaggingTest):
dog.tags.add("woof", "red")
self.assertEqual(list(Food.objects.filter(tags__in=["red"]).distinct()), [apple])
self.assertEqual(list(Food.objects.filter(tags="red").distinct()), [apple])
class TaggableFormTestCase(BaseTaggingTest):
def test_form(self):
......
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