-2

I made a simple login page with python and datastore. 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 GqlQuery?

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
user3167683
  • 131
  • 1
  • 1
  • 15

1 Answers1

1

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.)

1.

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

2.

user = User.all().filter('name =', 'John').filter('password =', '1234').get()
if user:
    user.name = 'Marcus'
    user.put()
  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.
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895