简体   繁体   中英

how to render django haystack search results in formset

I am using haystack for search. I need to allow the user to add additional data to search entries after a search and so I believe I need to use the search results in a formset or list of forms.

For example when search for food I would be able to add the serving size:

在此处输入图片说明

How can I accomplish this?

Your question does not contain enough information for a detailed answer but based on the information you've given I would suggest you take a look at creating unbound forms using the Django Formfactory and populating them with data.

You can then use these populated forms in the way you requested.

I'll give you some example code to get you started:

    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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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