我正在尝试设置 haystack,但我从一开始就有一些错误。
尝试打开搜索 url 时出现以下错误:

All 'SearchIndex' classes must use the same 'text' fieldname for the 'document=True' field. Offending index is '<subtitrari.search_indexes.PictureIndex object at 0x7f3a6819be20>'.

有关如何使其工作的任何线索?

谢谢你。

这是我的代码:

模型.py
class Picture(models.Model):
    imdb_id = models.CharField(max_length=9, blank=True)
    title = models.CharField(max_length=50)
    tv_show = models.BooleanField(default=False)
    genre = TaggableManager(verbose_name=u'Genres')
    poster = models.ImageField(upload_to=poster_path, blank=True, null=True)
    rating = models.FloatField(max_length=3, null=True, blank=True)
    votes = models.IntegerField(null=True,blank=True)
    release_date = models.CharField(max_length=4, null=True, blank=True)
    plot = models.CharField(max_length=100, null=True, blank=True)
    url = models.URLField(null=True, blank=True)
    trailer = models.URLField(null=True, blank=True)
    slug = models.SlugField(null=True, blank=True)

    @property
    def domain(self):
        return urlparse(self.url).netloc

    def natural_key(self):
        return self.title

     def __unicode__ (self):
        return self.title

search_indexes.py
import datetime

from haystack import indexes

from subtitrari.models import Picture

class PictureIndex(indexes.SearchIndex, indexes.Indexable):
    title = indexes.CharField(document=True, use_template=True)
    uploader = indexes.CharField(model_attr='uploader')
    created_at = indexes.DateTimeField(model_attr='created_at')

    def get_model(self):
        return Picture

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(created_at__lte=datetime.datetime.now())

最佳答案

按照教程,不要将文档字段名称更改为 title ,将其保留为 text

关于python - SearchFieldError Django 和 Haystack,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19069446/

10-13 01:20