Suraj Kapoor
Suraj Kapoor

Reputation: 1715

GQL Queries - Retrieving specific data from query object

I'm building a database using Google Datastore. Here is my model...

class UserInfo(db.Model):

name = db.StringProperty(required = True)
password = db.StringProperty(required = True)
email = db.StringProperty(required = False)

...and below is my GQL Query. How would I go about retrieving the user's password and ID from the user_data object? I've gone through all the google documentation, find it hard to follow, and have spent ages trying various things I've read online but nothing has helped! I'm on Python 2.7.

user_data = db.GqlQuery('SELECT * FROM UserInfo WHERE name=:1', name_in)
user_info = user_data.get()

Upvotes: 0

Views: 377

Answers (3)

user784435
user784435

Reputation:

There are some python tips that might help you

dir(user_info)
help(user_info)

you can also print almost anything, like

print user_info[0] 
print user_info[0].name

Setup logging for your app

Logging and python etc

Upvotes: 0

rGil
rGil

Reputation: 3719

You are almost there. Treat the query object like a class.

name = user_info.name

Documentation on queries here gives some examples

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 599460

This is basic Python.

From the query, you get a UserInfo instance, which you have stored in the user_info variable. You can access the data of an instance via dot notation: user_info.password and user_info.email.

If this isn't clear, you really should do a basic Python tutorial before going any further.

Upvotes: 1

Related Questions