Django haystack 搜索返回被排除的项目
我在 django-haystack 方面遇到了一些问题,需要一些帮助。
我运行一个对项目进行索引的网站,某些项目处于不应该被看到的状态,即 status='DE'
、status='PR'
我当前的设置是。
from haystack.indexes import *
from haystack import site
from models import Project
class ProjectIndex(RealTimeSearchIndex):
project_name = CharField(document=True, use_template=True)
description = CharField(use_template=True, model_attr='description')
location = CharField(use_template=True, model_attr='location')
owner = CharField(model_attr='owner')
def search(self):
return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')
def index_queryset(self):
"""Used when the entire index for model is updated."""
return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')
def get_queryset(self):
"""Used when the entire index for model is updated."""
return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')
def read_queryset(self):
"""Used when the entire index for model is updated."""
return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')
site.register(Project, ProjectIndex)
I have been having some issues with django-haystack and need some help.
I run a site that indexes projects and certain projects are in a status where they should not be seen, ie status='DE'
, status='PR'
my current setup is.
from haystack.indexes import *
from haystack import site
from models import Project
class ProjectIndex(RealTimeSearchIndex):
project_name = CharField(document=True, use_template=True)
description = CharField(use_template=True, model_attr='description')
location = CharField(use_template=True, model_attr='location')
owner = CharField(model_attr='owner')
def search(self):
return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')
def index_queryset(self):
"""Used when the entire index for model is updated."""
return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')
def get_queryset(self):
"""Used when the entire index for model is updated."""
return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')
def read_queryset(self):
"""Used when the entire index for model is updated."""
return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')
site.register(Project, ProjectIndex)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法通过从 1.1 更新到 1.2 来解决这个问题
,然后突然我开始收到这些
Caught VariableDoesNotExist while rendering: Failed Lookup for key [object] in u'None'
Google 了一下并发现了某些项目可能已从系统中消失,并且有一个方便的命令可以实现这一点。
现在我有一个 cronjob 每隔几个小时执行以下
/usr/bin/python2.6 /www/mysite/manage.py update_index --remove
I managed to solve this issue by updating from 1.1 to 1.2
then all of the sudden I started receiving these
Caught VariableDoesNotExist while rendering: Failed lookup for key [object] in u'None'
Googled it and found out that certain items might have disappeared out of the system and there is a handy command for that.
now I have a cronjob that does the following
/usr/bin/python2.6 /www/mysite/manage.py update_index --remove
every few hours