バックエンドとしてelasticsearchを使用していることに注意してください。
モデル ObjectA に関連付けられた Taggit タグが、django 設定を使用してインデックスに表示されないようです
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
を使用してインデックス ドキュメントを一覧表示すると、
http://localhost:9200/_search
DBに挿入したObjectAインスタンスのインデックスレコードを表示すると、「タグ」要素は次のように表示されます
"tags": []
それは私が走った後だけです
manage.py rebuild_index [or update_index]
タグは表示されますか
"tags": ["tag-a", "tag-b"]
興味深いのは、rebuild_index/update_index を実行しなくても、「タイトル」、「説明」が自動的に表示されることです。
objecta_text.txt
{{ object.title }}
{{ object.description }}
{% for tag in object.tags.all %} {{ tag.name }} {% endfor %}
search_indexes.py
class ObjectAIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')
description = indexes.CharField(model_attr='description', null=True)
tags = indexes.MultiValueField()
def get_model(self):
return ObjectA
def prepare_tags(self, obj):
return [tag.name for tag in obj.tags.all()]
rebuild_index を呼び出さずにタグをインデックス ドキュメントに表示する方法について何か提案はありますか?