如何在formset中呈现django haystack搜索结果
我在用干草堆搜索。我需要允许用户在搜索后向搜索条目添加额外数据,因此我认为我需要在表单集或表单列表中使用搜索结果 例如,在搜索食物时,我可以添加份量:如何在formset中呈现django haystack搜索结果,django,django-forms,django-haystack,Django,Django Forms,Django Haystack,我在用干草堆搜索。我需要允许用户在搜索后向搜索条目添加额外数据,因此我认为我需要在表单集或表单列表中使用搜索结果 例如,在搜索食物时,我可以添加份量: 我如何才能做到这一点?您的问题没有足够的信息提供详细的答案,但根据您提供的信息,我建议您考虑使用Django创建未绑定表单并用数据填充它们 然后,您可以按照请求的方式使用这些填充的表单 我将为您提供一些示例代码来帮助您开始: def _create_form_instances(self, model_name=None, exclud
我如何才能做到这一点?您的问题没有足够的信息提供详细的答案,但根据您提供的信息,我建议您考虑使用Django创建未绑定表单并用数据填充它们 然后,您可以按照请求的方式使用这些填充的表单 我将为您提供一些示例代码来帮助您开始:
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)