Author: floguy
Date: Sat Sep 20 20:34:27 2008
New Revision: 15
Modified:
trunk/things/options.py
Log:
Change the field lookup boolean operation from AND to OR.
Modified: trunk/things/options.py
==============================================================================
--- trunk/things/options.py (original)
+++ trunk/things/options.py Sat Sep 20 20:34:27 2008
@@ -1,10 +1,12 @@
import re
+from operator import or_
from django.conf.urls.defaults import *
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.template.loader import select_template
from django.core.urlresolvers import reverse
+from django.db.models import Q
from things.fields import BaseField
DETAIL_RE = re.compile('^(\d+)/$')
@@ -48,11 +50,11 @@
if terms and bool(self.search):
kwargs = {}
if isinstance(self.search, basestring):
- kwargs[self.search] = terms
+ items = items.filter(**{"%s__icontains" % self.search,
terms})
else:
- for search_field in self.search:
- kwargs['%s__icontains' % (search_field,)] = terms
- items = items.filter(**kwargs)
+ q_list = [Q(**{'%s__icontains' % s: terms}) for s in
self.search]
+ items = items.filter(reduce(or_, q_list))
+ items =
if field is not None:
pre = ''
if descending == True:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---