Created
          August 14, 2013 08:05 
        
      - 
      
- 
        Save toast38coza/6228903 to your computer and use it in GitHub Desktop. 
    Return all results from a Django-Haystack search even if there is no query provided
  
        
  
    
      This file contains hidden or 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 FacetedSearchForm | |
| class ShowResultsSearchForm(FacetedSearchForm): | |
| """ | |
| This example extends the FacetedSearchForm - you could just as easily extend SearchForm | |
| """ | |
| def __init__(self, *args, **kwargs): | |
| super(BrowseFilterSearchForm, self).__init__(*args, **kwargs) | |
| def no_query_found(self): | |
| """ | |
| Overwrite the defult no_query_found method - instead of returning empty query, return .all() | |
| """ | |
| return self.searchqueryset.all() | 
  
    
      This file contains hidden or 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 myapp.forms import ShowResultsSearchForm | |
| url(r'^$', FacetedSearchView( | |
| form_class=ShowResultsSearchForm, | |
| searchqueryset=SearchQuerySet().all()), | |
| name='haystack_faceted_search'), | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment