Django 管理 URL 查询字符串“OR”。是否可以?
我喜欢能够将快速而脏的查询字符串直接写入 Django 管理的 URL 中。例如:/admin/myapp/mymodel/?pub_date__year=2011
AND 语句也同样简单:/admin/myapp/mymodel/?pub_date__year=2011&author=Jim
I我想知道是否可以通过 URL 发出“OR”语句。有人听说过这样的功能吗?
I love being able to write quick and dirty query strings right into the URL of the Django admin. Like: /admin/myapp/mymodel/?pub_date__year=2011
AND statements are just as easy: /admin/myapp/mymodel/?pub_date__year=2011&author=Jim
I'm wondering if it's possible to issue an 'OR' statement via the URL. Anyone heard of such functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
姜戈1.4 不支持OR查询。有时可以将 OR 查询转换为受支持的 __in 查询(它们相当于 OR 查询,但仅适用于单个字段值)。
您还可以升级到 django 开发版本:它具有更通用的 list_filter 实现(请参阅 https://docs.djangoproject.com/en/dev//ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter )可用于提供高级管理过滤器(包括 OR 查询)。
Django < 1.4 doesn't support OR queries. Sometimes it is possible to translate OR queries to __in - queries which are supported (they are equivalent to OR queries but only for single field values).
You can also upgrade to django development version: it has more versatile list_filter implementation (see https://docs.djangoproject.com/en/dev//ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter ) which can be used for providing advanced admin filters (including OR-queries).
的&不是一个逻辑与,即使在你的情况下似乎是这样的。我非常确定没有办法在 GET 查询字符串中创建逻辑 OR。
The & is not a logical AND, even though it seems to be acting that way in your case. I'm pretty certain there is no way to create a logical OR in the GET query string.