views:

404

answers:

2

Hi, I am new to Google App Engine, I have this entites User class -
user_id - integer
user_name - string
password - string

I want to do auto increment for the user_id,How I can do this?

+5  A: 

You don't need to declare user_id, GAE will create a unique key id every time you insert a new row.

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

and to store a new user you will do:

user = User()
user.title = "Username"
user.password = "Password"
user.put()

to retrieve it:

user = User.get_by_id(<id of the user>)

to retrieve all the ids:

query = datamodel.User().all()
for result in query:
    print result.key().id()

See The Model Class for further reference.

systempuntoout
+1  A: 

Every entity in the AppEngine already has a unique key and id (see the documentation):

user().key().id()

You would be better off using that instead.

To do the converse, use User.get_by_id(id).

meeselet