【发布时间】:2012-04-04 10:56:41
【问题描述】:
我在使用 python 的谷歌应用引擎中有一个名为“客户”的模型:
class Customer(db.Model):
name = db.StringProperty()
age = db.IntegerProperty()
在我创建客户模型的任何实例/对象之前,我想检查模型是否为空(没有创建对象),我在 Python 中尝试了一些类似的东西:
customers = Customer.all()
for customer in customers:
if customer:
logging.info("there is customer in Customer Model!")
else:
logging.info("The Customer Model is empty!")
........
当Customer模型中没有实例/对象时,上面sn-p中的“customers”不是“None”,而“for customer in customers:”这行总是跳出来(意思是“customers”里面什么都没有?), 任何想法?另外,我可以在 Django 模板中检查这个吗? 提前谢谢你。
【问题讨论】:
标签: python django google-app-engine