Hi am going through the docs of GAE and needed a small clarification. If I have my db model something like this:-
class Phone(Model):
phone_name = db.StringProperty()
r = Phone(Nokia, key_name='first')
r.put()
Now if I have to retrieve this entity but I dont know the key, can I construct the key like this:
k=db.Key('Phone','first')
and once the key is constructed, can the entity be retrieved like this:-
r=db.get(k)
You’re close. The only major difference is
that you have to pass the actual class instead of a string representing the class name, andthat you have to use theKey.from_path()factory method rather than the default constructor:On the whole, however, I have found that relying on auto-generated IDs is usually a better solution than specifying your own key names. Is there a particular reason you’re doing the latter?