Created
February 2, 2010 12:38
-
-
Save sweemeng/292626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from haystack.forms import SearchForm | |
from django import forms | |
from haystack.query import SearchQuerySet | |
SEARCH_FILTER =[('all','all'),('name','name'),('business','sector'),('address','address')] | |
class FilterSearchForm(SearchForm): | |
def __init__(self,*args,**kwargs): | |
super(FilterSearchForm,self).__init__(*args,**kwargs) | |
self.fields['keys'] = forms.ChoiceField(choices=SEARCH_FILTER,required=True, | |
label='search in') | |
def search(self): | |
d = {} | |
sqs = super(FilterSearchForm,self).search() | |
key = str(self.cleaned_data['keys']) | |
data = str(self.cleaned_data['q']) | |
d[key] = data | |
if key == 'all': | |
return sqs | |
else: | |
print d | |
return sqs.filter(**d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment