Django 1.9 / Haystack 2.4.1 "Model not found for SearchResult"

Let me first say that I tried the fixes here:

Haystack says "Model not found for SearchResult"

and i still get

Model could not be found for SearchResult '<SearchResult: dictionary.termentry (pk=u'10')>'.

      

I am on Django 1.9 and Haystack 2.4.1 with Whoosh. I have determined that the SearchQuerySet is very well filtered (when I print queryset

get a list of objects SearchResult

). I haven't touched on anything other than the SearchIndex definition, so this is the finished story. For reference, here's the relevant bits of code:

in search_indexes.py:

class TermIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True,use_template=True)
    rendered = indexes.CharField(use_template=True,indexed=False)

    def get_model(self):
        return TermEntry

    def index_queryset(self,using=None):
        """Used when updating index for model"""
        return self.get_model().objects.all()

      

in views.py:

def search(request):
    query = ''
    queryset = None
    results = []
    showresults = True

    if request.method == 'GET' and request.GET.get('q'):
        form = SearchForm(request.GET)
        showresults = True

        query = request.GET.get('q')
        # making sure we got a query
        print query
        queryset = SearchQuerySet().filter(content=AutoQuery(query))
        # checking to see if we got anything in our queryset
        print queryset

        for q in queryset:
            print q
            results.append(q.object)

        # checking to see if we got any results
        print results

    else:
        form = SearchForm()
        showresults = False

    context_dict = {
        'query': query, 
        'results': results,
        'form': form,
        'showresults': showresults,
    }

    return render(request, 'search/search.html', context_dict)

      

I don't know what fix is ​​here, let alone the problem (I mean, the actual problem, I know I'm getting an error). My settings are pretty much a book, and I've bit / rebuilt the index probably eighty times. I don't have anything funky or interesting with my paths or my data structure, I don't use anything other than defaults for backends and databases, etc.

+1


source to share


1 answer


I have the same problem with Solr. Found the solution here: Haystack says "Model not found for SearchResult"

Basically, Haystack 2.4.1 uses the legacy Django call, this has been fixed in the latest version of the wizard.



So, I replaced django-haystack == 2.4.1 in my requirements with git + git: //github.com/django-haystack/django-haystack.git and it started working.

+5


source







All Articles