django-nonrel 谷歌应用引擎 order_by('?')

发布于 2024-09-29 02:56:56 字数 361 浏览 9 评论 0原文

我正在 Google App Engine 中开发 django-nonrel 应用程序。

我正在尝试以随机顺序从数据库返回项目。因此,我的 Items 模型中可能有 100 个项目。我希望退回随机选择的 20 件商品。

我尝试过使用:

Items.objects.order_by('?')[:20]

除了我收到以下错误:

Randomized ordering isn't supported by the backend

我认为这是 django-nonrel 对 GAE 的限制?

是否有其他方法可以用于 GAE 上的 django-nonrel 以获得相同的效果?

I am working on a django-nonrel app in Google App Engine.

I am trying to return items from a database in a random order. So I might have 100 items in my Items model. I wish to return a random selection of 20 items.

I have tried using:

Items.objects.order_by('?')[:20]

Except I get the following error:

Randomized ordering isn't supported by the backend

I take it this is a limitation of django-nonrel on GAE?

Is there an alternative method I could use for django-nonrel on GAE to get the same effect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

淡写薰衣草的香 2024-10-06 02:56:56

我已经设法找到解决方法。

我只是使用 python 的 random.shuffle(LIST_ITEM) 作为执行此操作的方法。

最后其实很简单。

I've manage to find a workaround for this.

I just used python's random.shuffle(LIST_ITEM) as a way fo doing this.

It was actually very simple in the end.

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