I recently switched from ext.db to NDB.model on Google App Engine and still fairly new to database in general. Below is the new NDB code, which is mostly unchanged from ext.db.
What I want to do is when a user tries to login, check if uid exists. If so, pass back the data from database as "entry." If uid does not exist, then pull the data from Json and populate the new "entry."
class User(ndb.Model):
uid = ndb.StringProperty(required = True)
firstName = ndb.StringProperty(required = True)
lastName = ndb.StringProperty(required = True)
emailAddress = ndb.StringProperty(required = True)
password = ndb.StringProperty(required = True)
created = ndb.DateTimeProperty(auto_now_add = True)
last_modified = ndb.DateTimeProperty(auto_now = True)
@classmethod
def addUser(cls, info):
entry = User.query().filter(Profile.uid == info['uid']).get
#USED TO BE FOR DB: entry = User.all().filter('uid = ', info['uid']).get()
# if the profile doesn't exist, create it with basic information
if entry == None:
entry = User(uid = info["id"],
firstName = info["firstName"],
lastName = info["lastName"],
emailAddress = info["emailAddress"],
password = info[passwd])
# At this point, we have a valid entry.
entry.last_modified = datetime.now()
entry.put()
return entry
This code does NOT work. I have tried entry = User.query().filter(Profile.uid == info['uid']).get but I get an attribute error
AttributeError: 'instancemethod' object has no attribute 'last_modified'
I apologize for unable to clarify more, but am stuck. What am I missing? Everything worked fine with ext.db (note where I changed as noted in the code above), but I cannot see what is wrong with NDB. I am seeking improvements as well, so please suggest changes.
Any help is greatly appreciated! Thank you.