python-SearchFieldError Django和Haystack
作者:互联网
我正在尝试设置干草堆,但从一开始我就有一些错误.
尝试打开搜索网址时出现以下错误:
All 'SearchIndex' classes must use the same 'text' fieldname for the 'document=True' field. Offending index is '<subtitrari.search_indexes.PictureIndex object at 0x7f3a6819be20>'.
关于如何使其工作的任何线索?
谢谢.
这是我的代码:
models.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())
解决方法:
按照教程进行操作,不要将文档字段名称更改为标题,而是将其保留为文本.
标签:python,django,django-haystack 来源: https://codeday.me/bug/20191030/1967349.html