I'm facing a problem with code organization with GAE, so i'm trying this
solution below. I created a global list wich will contains all Restaurant
objects reference, i know that is not good programming practice and here i
go with my doubt: is there some how i lost every Restaurant references
appended on the list? Like Google server go down and lost?
ALL_RESTAURANTS = []
class Establishment(db.Model):
name = db.StringProperty()
email = db.StringProperty()
orders = db.StringProperty()
products = db.StringProperty()
state = db.StringProperty()
class Restaurant(object):
def __init__(self,name,email):
self.name = name
self.email = email
def save(self):
que = db.Query(Establishment)
que.filter('email =',self.email)
results = que.fetch(limit=1)
if len(results)>0:
logging.info('Already exist a restaurant associated to this
email')
return False
else:
restaurant =
Establishment(name=self.name,email=self.email,products='empty',orders='empty',state='OFFLINE')
restaurant.put()
logging.info('Restaurant '+self.email+' saved in DB!')
return True
class TheHandler(webapp2.RequestHandler):
def get(self):
newRestaurant = Restaurant(name='The
Pizza',email='[email protected]')
newRestaurant.save()
ALL_RESTAURANTS.append(newRestaurant)
anotherRestaurant = Restaurant(name='The Other
Pizza',email='[email protected]')
anotherRestaurant.save()
ALL_RESTAURANTS.append(anotherRestaurant)
Best Regards...
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-appengine/84df9e5c-3bba-4ec0-8cd9-238c8110e90f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.