haystack SearchQueryResult对象返回多个对象

时间:2013-06-07 14:52:50

标签: django-haystack searchqueryset

我不明白为什么用pk = 1的get()会导致在下面返回多个对象..

sqs = SearchQuerySet().more_like_this(self)

for obj in sqs:
      do something with obj.object # obj.object results in error

get()返回多个MyModel - 它返回4!查找参数是{'pk':u'1'}

1 个答案:

答案 0 :(得分:0)

我不知道为什么,但我遇到了同样的问题,以下给了我MultipleObjectReturned错误:

context['object_list'] = [result.object for result in results]


lib/python2.7/site-packages/haystack/models.py", line 80, in _get_object
self._object = self.searchindex.read_queryset().get(pk=self.pk)

而不是直接引用obj.object,我使用了pk

context['object_list'] = Entry.objects.filter(pk__in=[result.pk for result in results])