user3167683 user3167683 - 1 year ago 67
Python Question

Google App Engine Datastore delete entity by properties

I made a simple login page with

. the User model is the following.

class User(db.Model):
name = db.StringProperty()
password = db.StringProperty()

Question 1:

Lets say that I know the name and the password of a specific user. How can I delete that entity from the database that has the specified name and password properties?

Question 2:

Lets say that I have a User entity with "John" as the name and "1234" as the password. Given these 2 things, how can I change the name property "John" to "Marcus"?

Question 3:

Is it possible to achieve this without using

Answer Source

These things are very well explained in the documentation. (Which also states clearly that you should not be using the old db API, but the ndb one, but never mind.)


user = User.all().filter('name =', name).filter('password =', password).get()
if user:


user = User.all().filter('name =', 'John').filter('password =', '1234').get()
if user: = 'Marcus'
  1. There is nothing that requires GqlQuery. GQL is simply another interface to the underlying datastore RPCs: it is not in any sense more "native" than the db or ndb APIs, and those do not "compile down" to GQL in the same way that (eg) Django's ORM compiles down to SQL.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download