我试图让一个MultiValueField
被编入索引,但它只是不工作。 以下是我有:
class Public_PollIndex(SearchIndex): text = CharField(model_attr='question', document=True, use_template=True) date_created = DateTimeField(model_attr='date_created') choices = MultiValueField() def get_model(self): return Public_Poll def prepare_choices(self, obj): # For some silly reason we get (u"choice",) instead of just u"choice" # So we unpack... c = [ str(c) for (c,) in obj.choice_set.values_list('choice') ] return c def index_queryset(self): return self.get_model().objects.filter(date_created__lte=datetime.datetime.now())
然后,我有模板:
{{ object.question }} {{ object.date_created }} {{ object.choices }}
与调试器步进通过prepare_choices
不会返回类似['foo', 'bar']
但是,当我看着Solr的或Public_PollIndex(Public_Poll.objects.get(id=1)).load_all_queryset()
我没有看到choices
字段建立索引,但其他两个。