Fixed a bug so that `ValuesListQuerySet now works with the __in` filter.

This commit is contained in:
Daniel Lindsley 2011-05-03 15:03:29 -05:00
parent 9afba72cae
commit 3b3834d8ed
2 changed files with 9 additions and 0 deletions

View file

@ -159,3 +159,8 @@ class XapianSearchQueryTestCase(TestCase):
def test_build_query_with_punctuation(self):
self.sq.add_filter(SQ(content='http://www.example.com'))
self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((Zhttp://www.example.com OR http://www.example.com))')
def test_in_filter_values_list(self):
self.sq.add_filter(SQ(content='why'))
self.sq.add_filter(SQ(title__in=MockModel.objects.values_list('id', flat=True)))
self.assertEqual(str(self.sq.build_query()), u'Xapian::Query(((Zwhi OR why) AND (ZXTITLE1 OR XTITLE1 OR ZXTITLE2 OR XTITLE2 OR ZXTITLE3 OR XTITLE3)))')

View file

@ -954,6 +954,10 @@ class SearchQuery(BaseSearchQuery):
expression, term = child
field, filter_type = search_node.split_expression(expression)
# Handle when we've got a ``ValuesListQuerySet``...
if hasattr(term, 'values_list'):
term = list(term)
if isinstance(term, (list, tuple)):
term = [_marshal_term(t) for t in term]
else: