Permalink
Browse files

Removed some print statements. Added none() method to querysets. Sphi…

…nxModelAdmin no longer shows results unless a filter or query is present.
  • Loading branch information...
1 parent 4a13964 commit 1454ee53eb5ec9c11d73ae46457a641092f68ec3 David Cramer committed Mar 15, 2010
Showing with 17 additions and 3 deletions.
  1. +4 −1 djangosphinx/admin.py
  2. +13 −2 djangosphinx/models.py
View
5 djangosphinx/admin.py
@@ -68,9 +68,12 @@ def get_query_set(self):
qs = qs.order_by('%s%s' % ((self.order_type == 'desc' and '-' or ''), self.order_field))
if self.query:
- print self.query
qs = qs.query(self.query)
+ if not (lookup_params or self.query):
+ # We don't show bare result sets in Sphinx
+ return qs.none()
+
return qs
def get_results(self, request):
View
15 djangosphinx/models.py
@@ -330,7 +330,12 @@ def geoanchor(self, lat_attr, lng_attr, lat, lng):
# keep things looking/working generally the same
def all(self):
return self
-
+
+ def none(self):
+ c = EmptySphinxQuerySet()
+ c.__dict__.update(self.__dict__.copy())
+ return c
+
# only works on attributes
def exclude(self, **kwargs):
filters = self._excludes.copy()
@@ -658,6 +663,10 @@ def _get_passages(self, instance, fields, words):
c += 1
return passages
+class EmptySphinxQuerySet(SphinxQuerySet):
+ def _get_sphinx_results(self):
+ return None
+
class SphinxModelManager(object):
def __init__(self, model, **kwargs):
self.model = model
@@ -673,6 +682,9 @@ def get_index(self):
def all(self):
return self._get_query_set()
+ def none(self):
+ return self._get_query_set().none()
+
def filter(self, **kwargs):
return self._get_query_set().filter(**kwargs)
@@ -710,7 +722,6 @@ def __call__(self, index, **kwargs):
def __get__(self, instance, model, **kwargs):
if instance:
- print instance
return SphinxInstanceManager(instance, self._index)
return self._sphinx

0 comments on commit 1454ee5

Please sign in to comment.