user3167683 user3167683 - 2 months ago 9
Python Question

Google App Engine Datastore get value of property

I have some questions. Suppose we have this Model for Datastore:

class SessionID(db.Model):
SESSIONID = db.StringProperty()
userid = db.StringProperty()
userip = db.StringProperty()
exp_time = db.IntegerProperty()


Lets say we registered the SESSIONID property to 1234, assigned userid to bob, the userip to 123.123.123.123, and the exp_time to 1

Question 1:
Suppose we know the SESSIONID value. Using that value, how can I get the value of userid?

Answer
from models import User 
# Assuming you have user model class in models
user = User.query().filter(User.SESSIONID==1234).get()

Now user will contain object or objects(depending on uniqueness of SESSIONID) of User class, so to get userid just do:

id = user.userid

Hope it helps.

PS: Read the documentation mentioned by Daniel, that will help you a lot.

Comments