簡體   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