Thanks for the answer.
Basing in what you said, i have a few questions:
- I really forgot the point of multiple instances, lol.
- Why should i use ndb instead db?
- Actually this questions of save orders and products leaves me with 
insomnia, because i need to decide how to construct the appropriate data 
structure. I raised the hypothesized of create a "code" for each product, 
because i need to send a product list and orders to a .js client via 
channel API. In first attempt i tried to store a dictionary, but did not 
work so a converted in to a string. However, i guess i got your suggestion, 
if i have different data models i cand bind them from the key (email).
 - you said: "You might not need any (most) of the indexes", can you please 
show me an example?

Best Regards! 

Em terça-feira, 27 de janeiro de 2015 13:57:19 UTC-2, Mihail Russu escreveu:
>
> 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]')
>>         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/41604f50-677e-46f9-bf29-4f1cd63251b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to