I have a model called “Customer” in google app engine with python:
class Customer(db.Model):
name = db.StringProperty()
age = db.IntegerProperty()
before I create any instance/object of the Customer model, I would like to check if the model is empty(no object has been created), I tried something in Python like:
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!")
........
when there is no instance/object in Customer model, “customers” in above snippet is not “None”, while the line “for customer in customers:” always jumps out(means there is nothing in “customers”?), any idea? in addition, can I check this in Django template?
thank you in advance.
you could use count()