如何从 Haystack SearchQuerySet 中删除项目

发布于 2024-12-24 01:52:30 字数 450 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

走野 2024-12-31 01:52:30

您是否尝试过使用排除? IE

searchqueryset = searchqueryset.exclude(id=u'myapp.mymodel.%s' % item.pk)

Have you tried using exclude? I.e.

searchqueryset = searchqueryset.exclude(id=u'myapp.mymodel.%s' % item.pk)
小霸王臭丫头 2024-12-31 01:52:30

我在此解决方案中看到的一个问题是 searchqueryset 是否搜索不同的模型。然后,您将使用 pk = item.pk 排除所有对象,这是您不希望执行的操作。

这是我使用的方法。我将 searchqueryset 转换为一个列表:

searchqueryset_list = list(searchqueryset)

然后我可以删除该项目:

searchqueryset_list.remove(item)

虽然 *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:

searchqueryset_list = list(searchqueryset)

Then I could remove the item:

searchqueryset_list.remove(item)

Although *searchqueryset_list* is not a SearchQuerySet object, I could use it in the templates that render the html page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文