Yes, your ALL_RESTAURANTS list will not always contain the full list of
Restaurants for many reasons, including the ones you provided.
Also, there are some more things I noticed in your code at a glance:
- Your project will run on multiple instances meaning each instance will
have its own copy of ALL_RESTAURANTS so you will likely not be getting any
consistent results of what's in the ALL_RESTAURANTS list.
- You should be using NDB instead of older DB
- It *might *be a good idea to have "orders" and "products" properties as
separate data models rather than strings.
- Since one email seem to only have one restaurant you could use the email
address as the "id" of the restaurant, this would let you do free "get by
id" rather than expensive queries queries.
- You might not need any (most) of the indexes (i.e. you need to specify
indexed=False next to each property that you do not want to be indexed)
Thanks,
Mihail.
On Tuesday, January 27, 2015 at 1:03:21 PM UTC+2, Saturnino Mateus wrote:
>
> 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] <javascript:>')
> newRestaurant.save()
> ALL_RESTAURANTS.append(newRestaurant)
>
> anotherRestaurant = Restaurant(name='The Other Pizza',email='
> [email protected] <javascript:>')
> 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/22b7411f-6dd4-4cdc-92d0-9ba5244cb177%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.