jabez jabez - 1 month ago 19
Python Question

SearchFieldError Django and Haystack

I'm trying to setup haystack but I have some errors from the beginning.
I have the following error when trying to open search 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>'.


Any clue of how to make it working?

Thank you.

Here is my code:

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())

Answer

Follow the tutorial, don't change the document field name into title, leave it as text.

Comments