I'm trying to group search results from Haystack. I want them to be grouped by model (Artist or Painting), then by a date field (created), then ideally by a boolean field (sold).
I.e. something like the following but it's not working. I think I need to override SearchView and somehow process the query before it's handed to the template but I'm not sure how.
Or perhaps I should just be doing the grouping in the template?
def get_queryset():
q = SearchQuerySet().filter(display=True).order_by('-created')
paintings_unsold = q.models(Painting).filter(sold=False)
paintings_sold = q.models(Painting).filter(sold=True)
artists = q.models(Artist)
return paintings_unsold | paintings_sold | artists
urlpatterns += patterns(
'',
(r'^search/', SearchView(
searchqueryset=get_queryset()
))
)