Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

query.filter and gql

I am trying this function, however something is wrong. I stored the name "John" but when i pass the john to username_ and call the check_user the output is always return results, even if the name is not stored in google data store. Why?

def check_user(self, username_):
    query = db.Query(Registrations)
    results = query.filter('username =', username_)
    if results:
        return results

user_username = self.request.get('username')
check_username_valid = self.check_user(user_username)

 if not check_username_valid:
    error_username_exists="Username already exists"

In the case of GQL, how can i pass the variable username_ into the query? like:

 qr = db.GqlQuery("Select * from Registrations Where username = ?????")
like image 216
daniel__ Avatar asked Jul 26 '26 12:07

daniel__


1 Answers

results is the query object not the result, you need to call query.filter('username =', username_).get() to return a single result or query.filter('username =', username_).fetch() to return all of them.

like image 111
Shay Erlichmen Avatar answered Jul 28 '26 01:07

Shay Erlichmen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!