我正在尝试创建(类似)发票号码生成器。但是,由于开办企业时发票可能为零或更多,您如何知道实体是否存在?
query = "SELECT loanNumber FROM Loans ORDER BY loanNumber DESC LIMIT 1"
loanNumbers = db.GqlQuery(query)
result = loanNumbers.get()
# for loanNumber in loanNumbers:
if loanNumbers is None:
print "Print the first number"
else:
print "Print the next number"
错误
KindError: No implementation for kind 'Loans'
答案 0 :(得分:3)
现在有一些很好的元数据帮助函数记录在这里:https://developers.google.com/appengine/docs/python/datastore/metadataentityclasses#get_kinds
以下是在继续查询和其余代码之前检查Loans
的示例:
from google.appengine.ext.db import metadata
my_kinds = metadata.get_kinds() # Returns a list of entity kind names.
if u'Loans' in my_kinds:
...
请注意,my_kinds
在实际创建贷款实体之前不会包含Loans
。
如果您需要更多控制权,或者更愿意推出自己的帮助程序功能,可以在此处举例说明:https://developers.google.com/appengine/docs/python/datastore/metadataqueries#Kind_Queries