所以我有以下型号:
class Article(models.Model, PublicationMixin):
publication = models.ForeignKey('Publication', related_name="articles")
...
class Publication(models.Model, PublicationMixin):
is_visible = models.BooleanField(default=False)
is_approved = models.BooleanField(default=False)
....
在search_indexes.py
我有:
class PublicationIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
id = indexes.CharField(model_attr='id', null=True)
我正在尝试应用进入searchform
的过滤器,并仅返回包含文章的出版物。
如何使用haystack及相关名称实现这一目标?我使用弹性搜索作为后端。
答案 0 :(得分:0)
您是否曾尝试在索引中引用articles字段,如下所示:http://django-haystack.readthedocs.org/en/latest/searchindex_api.html#advanced-data-preparation然后使用SearchQuerySetApi检索所需的值:http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html
:)