Django で Haystack を使用して SearchIndex を作成しようとしたときに問題が発生し、どうすればよいかわかりません。
ここに私の2つのモデルがあります:
# Meta: stores meta data about tutorials (category, title)
class Meta(models.Model):
"""
Database [tutorial.meta]
"""
mta_title = models.CharField(max_length=TUTORIAL_TITLE_MAX)
mta_views = models.PositiveIntegerField(default=0)
# Contents: stores the tutorial text content
class Contents(models.Model):
"""
Database [tutorial.contents]
"""
tut_id = IdField()
cnt_body = BBCodeTextField()
ここで、mta_title、mta_views、および cnt_body の 3 つのフィールドに基づいて SearchIndex を作成したいと考えています。これが私の現在のSearchIndexです:
from haystack import indexes
from tutorial.models import Meta as TutorialMeta
from account.models import Profile as UserProfile
class TutorialMetaIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='mta_title')
views = indexes.CharField(model_attr='mta_views')
# Haystack reserves the content field names for internal use
cnt_body = indexes.CharField()
def get_model(self):
return TutorialMeta
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()
def prepare_cnt_body(self, obj):
????
私はこの質問を見てきましたが、答えはprepare_cnt_bodyを作成することでした。でも何を返せばいいのかわからない。
みんなありがとう。