如何从 Haystack SearchQuerySet 中删除项目
在 Django 中,您可以按照此处:
queryset = QuerySet.remove(item)
Haystack SearchQuerySet 是基于 QuerySet 构建的,但似乎未实现删除方法。有谁知道删除 SearchQuerySet 中的项目的方法?
FWIW我正在尝试为客户进行第二级过滤。基本上,我正在对 SearchQuerySet 进行交互以获取几个特定属性。我的想法是,如果他们没有,我想删除它们。
谢谢
In Django you can remove items from a QuerySet by doing this as documented here:
queryset = QuerySet.remove(item)
Haystack SearchQuerySet is build on QuerySet but it appears that the remove method was not implemented. Does anyone know of a way to remove items in a SearchQuerySet?
FWIW I am trying to do a second level of filtering for a client. Basically I'm interating over the SearchQuerySet for a couple specific properties. The idea is if they don't have it I want to remove them.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过使用
排除
? IEHave you tried using
exclude
? I.e.我在此解决方案中看到的一个问题是 searchqueryset 是否搜索不同的模型。然后,您将使用
pk = item.pk
排除所有对象,这是您不希望执行的操作。这是我使用的方法。我将 searchqueryset 转换为一个列表:
然后我可以删除该项目:
虽然 *searchqueryset_list* 不是 SearchQuerySet 对象,但我可以在呈现 html 页面的模板中使用它。
One problem I see with this solution is if the searchqueryset searches through different models. You'll then exclude all objects with
pk = item.pk
, which you do not want to do.Here's the approach I used. I transformed searchqueryset to a list:
Then I could remove the item:
Although *searchqueryset_list* is not a SearchQuerySet object, I could use it in the templates that render the html page.