Keys or identifiers in Google App Engine with Python

Chiya, I asked a question earlier regarding the use of keys, which were answered.

However, now I'm wondering how to create and use keys for my models, my iPhone guy told me that we need INTs to store in the database. I got Python code working with Keys, and now I may have to step back.

I would be happy to hear your opinion on how to create key names and automatically generate identifiers that my iPhone application can use without any major changes.

Here are my models:

class User(db.Model):
   id = db.StringProperty()
   name = db.StringProperty()
   image = db.BlobProperty(default=None)

class Book(db.Model):
   image = db.BlobProperty()
   date_added = db.DateTimeProperty(auto_now_add=True)
   is_active = db.BooleanProperty(default=True)

class BookUser(db.Model):
   book = db.ReferenceProperty(Book)
   user = db.ReferenceProperty(User)
   is_active = db.BooleanProperty(default=True)

(). , BookUser, , . iPhone . , , , iPhone " ":)

?

### Get the Users Details
user_id = 1
user = User.get_by_key_name(user_id)
user_key = user.key().name()

### Get the latest active Book
book = Book.all().filter('is_active =', True).get()
book_key = book.key().name()

### Get latest Book for this User
bookuser_key_name = "%s:%s" % (str(book_key), str(user_key))
bookuser = BookUser.get_or_insert(bookuser_key_name)
bookuser.card = card
bookuser.user = user
bookuser.put()
+3
2

, , "id" . () . http://code.google.com/appengine/docs/python/datastore/keyclass.html

user_id - .

"iPhone-", ints, . int . , , , .

+1

, . iPhone , , ?

0

Source: https://habr.com/ru/post/1788358/


All Articles