繁体   English   中英

如何在formset中呈现django haystack搜索结果

[英]how to render django haystack search results in formset

我正在使用干草堆进行搜索。 我需要允许用户在搜索后向搜索条目添加其他数据,因此我相信我需要在表单集或表单列表中使用搜索结果。

例如,当搜索食物时,我可以添加份量:

在此处输入图片说明

我该怎么做?

您的问题没有足够的信息来提供详细的答案,但是根据您所提供的信息,我建议您看一下使用Django Formfactory创建未绑定的表单并将其填充数据的方法。

然后,您可以按照请求的方式使用这些填充的表单。

我将为您提供一些示例代码,以帮助您入门:

    def _create_form_instances(self, model_name=None, exclude=None):
        """Creates an form instance for the provided model_name"""

        for content_type in self.content_types:
            if model_name == content_type._meta.object_name:
                form = modelform_factory(content_type, exclude=exclude)

                return form

     #The following code comes from a different function:

     unbound_form = self._create_form_instances(
                    model_name=item._meta.object_name,
                    exclude=('page', 'content_html'))

                instance_to_form_mapping = {'content': item.content}

                bound_form = unbound_form(instance_to_form_mapping)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM