【问题标题】:AppEngine: Query datastore for records with no condition for a specific propertyAppEngine:查询数据存储以获取没有特定属性条件的记录
【发布时间】:2010-10-05 00:22:40
【问题描述】:

我想做一个用户可能会或可能不会选择过滤器的查询,但我不想创建 2 个索引(表)。

value=self.request.get('filter')
if value:
    results=Entity.all().filter('p1 =','v1').filter('p2 =','v2').filter('filter_property =',value)
else:
    results=Entity.all().filter('p1 =','v1').filter('p2 =','v2')

我可以订购 filter_property。像最后一行这样:

    results=Entity.all().filter('p1 =','v1').filter('p2 =','v2').order('filter_property')

如果我可以或不能过滤 p1 (property1) 和 p2 (property2),这将很糟糕。我想做类似的事情:

value = self.request.get('filter')
if value:
    operator = '='
else:
    operator = '!='
results=Entity.all().filter('p1 =','v1').filter('p2 =','v2').filter('filter_property '+operator,value).order('p4')

".order('p4')" 将失败 BadArgumentError 操作数 !=.

我该怎么办?

【问题讨论】:

    标签: python google-app-engine google-cloud-datastore


    【解决方案1】:

    听起来您已经很好地掌握了替代方案。如果您希望数据存储对每个过滤器使用相同的索引,则可以添加 order 子句来替换过滤器;否则,您将无法拥有多个索引。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      • 2023-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      相关资源
      最近更新 更多