刚刚开始使用Whoosh + Haystack。
我测试了一个测试模型,该模型索引很好并给出了结果。但索引在第二个模型(重要的一个)上由于某种未知原因而失败
这是模型
class Sale(models.Model):
brand = models.ForeignKey('Brand', related_name='sales_p')
outlets = models.ManyToManyField('Outlet', null=True, blank=True, related_name='sales')
child_brands = models.ManyToManyField('Brand', null=True, blank=True, related_name='sales_c')
child_categories = models.ManyToManyField('Category', null=True, blank=True, related_name='sales_c')
#collecting subcategories for subcategory sale
child_subcategories = models.ManyToManyField('SubCategory', null=True, blank=True,related_name='subcategory')
此搜索索引为
class SaleIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
outlets = indexes.CharField(model_attr='outlets')
child_brands = indexes.CharField(model_attr = 'child_brands')
child_categories = indexes.CharField(model_attr = 'child_categories')
child_subcategories = indexes.CharField(model_attr = 'child_subcategories')
content_auto = indexes.CharField(model_attr='brand')
def get_model(self):
return Sale
def index_queryset(self, using=None):
return Sale.objects.all()
def prep_childbrands(self, object):
return [brand.name for brand in self.child_brands.all()]
世界上没有其他人似乎曾经面对这一点。我是一般的编程新手。有什么我想念的东西是显而易见的吗?
追溯如果有帮助:
Indexing 84 Sales
ERROR:root:Error updating website using default
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/haystack/management/commands/update_index.py", line 189, in handle_label
self.update_backend(label, using)
File "/usr/local/lib/python3.4/dist-packages/haystack/management/commands/update_index.py", line 234, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity)
File "/usr/local/lib/python3.4/dist-packages/haystack/management/commands/update_index.py", line 89, in do_update
backend.update(index, current_qs)
File "/usr/local/lib/python3.4/dist-packages/haystack/backends/whoosh_backend.py", line 191, in update
doc = index.full_prepare(obj)
File "/usr/local/lib/python3.4/dist-packages/haystack/indexes.py", line 207, in full_prepare
self.prepared_data = self.prepare(obj)
File "/usr/local/lib/python3.4/dist-packages/haystack/indexes.py", line 198, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj)
File "/usr/local/lib/python3.4/dist-packages/haystack/fields.py", line 159, in prepare
return self.convert(super(CharField, self).prepare(obj))
File "/usr/local/lib/python3.4/dist-packages/haystack/fields.py", line 106, in prepare
return current_object()
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 843, in __call__
manager = getattr(self.model, kwargs.pop('manager'))
KeyError: 'manager'
答案 0 :(得分:0)
Haystack + Django 1.7中似乎存在导致此错误的错误。在其他问题中也引用了这个问题,因为Xapian提到(我们使用的是Whoosh),我没有注意到这个问题
Django-haystack with xapian engine: can't execute update_index if model has ManyToManyField