Django haystack搜索返回被排除的项目

ApP*_*PeL 2 django 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)
Run Code Online (Sandbox Code Playgroud)

ApP*_*PeL 5

我设法通过从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每隔几个小时执行以下操作