2011-04-08 110 views
7

从我读过的东西,这是我应该怎么检查任何记录......检查在App Engine数据存储中存在记录

v = PC_Applications.all().filter('column =', value) 
if not v: 
    return False 

但这返回一个错误!

IndexError: The query returned fewer than 1 results

任何想法做到这一点?我读过.count()是一个不错的选择。我是Python和App Engine的新手,非常感谢您的耐心等待!

回答

7
if not v.get(): 

App Engine, Query Class get()

Executes the query, then returns the first result, or None if the query returned no results.

+0

谢谢!我没有仔细阅读文档。 – Ryan 2011-04-09 11:25:04

3

这应该工作:

q = db.Query(PC_Applications, keys_only = True) 
if not q.get(): 
    return false 

我觉得.all().filter('column =', value).count更糟糕,因为它不是做纯键查询。

0

如果你真的想使用的记录,这样做:

results = PC_Applications.all().filter('column =', value).fetch(how_many_you_want) 
if results: 
    do_something_to_display_them() 
else: 
    do_something_else() 
相关问题