【发布时间】:2013-11-14 11:51:14
【问题描述】:
这让我有点生气,但看起来应该很简单。
我正在使用 Django 和 Haystack,并且有一个搜索索引,其中包括一个允许为空的 IntegerField。这是基于 Django 中的相关模型,但我认为这并不重要。例如:
class ThingIndex(indexes.ModelSearchIndex, indexes.Indexable):
group = indexes.IntegerField(model_attr='group__id', null=True)
class Meta:
model = Thing
有时我希望我的 Haystack 查询为此字段返回具有 None/Null 的项目,因此我在搜索表单的 __init__ 中进行过滤,但我无法获得执行此操作的查询。我尝试过的最明显的方法是:
self.searchqueryset.filter(group__isnull=True) # how to do it on a regular Django queryset
但这不会返回任何记录。
现在我正在解决这个问题:
self.searchqueryset.exclude(group__in=range(1,100))
这行得通,但显然不应该这样做:)
谁能帮忙?
谢谢!
【问题讨论】:
标签: python django django-haystack