Django 1.9 / Haystack 2.4.1“SearchResult找不到模型” [英] Django 1.9/Haystack 2.4.1 "Model could not be found for SearchResult"

查看:153
本文介绍了Django 1.9 / Haystack 2.4.1“SearchResult找不到模型”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我先说说,我在这里尝试过修复:





,我仍然得到

  SearchResult'< SearchResult找不到模型:dictionary.termentry(pk = u'10 ')>'。 

我在Django 1.9& Haystack 2.4.1与Whoosh。我确定SearchQuerySet正在过滤(当我 print queryset 我得到一个 SearchResult 对象的列表) 。我没有触摸任何超出SearchIndex定义的东西,所以这是开箱即用的东西。仅供参考,以下是相关的代码:



在search_indexes.py中:

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

def get_model(self):
return TermEntry

def index_queryset(self,using = None):

return self.get_model()。objects.all()

in views.py:

  def search(request):
query =''
queryset =无
结果= []
showresults = True

如果request.method =='GET'和request.GET.get('q'):
form = SearchForm(request.GET)
showresults = True

query = request.GET.get('q')
#确保我们得到一个查询
打印查询
queryset = SearchQuerySet()。filter(content = AutoQuery(query))
#检查我们的查询中是否有任何东西
print queryset

q在查询中:
打印q
results.append(q.object)

#查看是否有任何结果
打印结果

else:
form = SearchForm()
showresults = False

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

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

我不知道这里的修复是什么,更不用说问题(我的意思是,问题;我知道我收到一个错误)。我的设置是所有的本本,我已经nuked /重建索引大概八十次。我的路径或数据结构没什么好玩的,我没有使用任何东西,除了默认的后端和数据库等等。

解决方案

我和Solr有同样的问题。在这里找到解决方案: Haystack说:找不到模型SearchResult



基本上,Haystack 2.4.1使用过时的Django调用,这是最新的主机修复。



所以我已经用git + git://github.com/django-haystack/django-haystack.git替换了django-haystack == 2.4.1,并开始工作。 / p>

Let me just first say, I have tried the fixes here:

Haystack says "Model could not be found for SearchResult"

and I'm still getting

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

I'm on Django 1.9 & Haystack 2.4.1 with Whoosh. I've determined that the SearchQuerySet is filtering just fine (when I print queryset I get a list of SearchResult objects). I didn't touch anything beyond the SearchIndex definitions, so this is out-of-the-box stuff. Just 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 the fix is here, let alone the problem (I mean, the actual problem; I know I'm getting an error). My settings are all by-the-book, and I've nuked/rebuilt the index probably eighty times. I don't have anything funky or fancy going on with my paths or my data structure, I'm not using anything but defaults for backends and databases and such.

解决方案

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

Basically, Haystack 2.4.1 uses the outdated call to Django, this was fixed in latest the master.

So I've replaced django-haystack==2.4.1 in my requirements with git+git://github.com/django-haystack/django-haystack.git and it started to work.

这篇关于Django 1.9 / Haystack 2.4.1“SearchResult找不到模型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆