I’m trying to create (something like) an invoice number generator. But, since Invoices may be zero or more when starting a business, how do you know if an entity exists?
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"
Error
KindError: No implementation for kind 'Loans'
Now there are some nice metadata helper functions documented here: https://developers.google.com/appengine/docs/python/datastore/metadataentityclasses#get_kinds
Here is an example of checking for
Loansbefore continuing with your query and the rest of your code:Note that
my_kindswill not containLoansuntil a loan entity has actually been created.If you require more control, or prefer to roll your own helper function there are examples of that here: https://developers.google.com/appengine/docs/python/datastore/metadataqueries#Kind_Queries