Why the model has a key name, does not have a key (). id () in google-app-engine

if i use this:

class A(db.Model):
    a=db.StringProperty()

class demo(BaseRequestHandler):
    def get(self):
        a=A()
        a.a='sss'
        a.put()
        raise Exception(a.key().id())

I can get a.key (). id () - 961

but if I add key_name = "aaa", a.key (). id () will be None:

class A(db.Model):
    a=db.StringProperty()

class demo(BaseRequestHandler):
    def get(self):
        a=A(key_name="aaa")
        a.a='sss'
        a.put()
        raise Exception(a.key().id())

since I can get the key (). id () when I set key_name

thank

+3
source share
1 answer

You cannot, because it is one and the same.

The fact that entities have an encoded string key plus either an integer identifier or a string name can give the erroneous impression that the various ways of referencing an object are overlapping or redundant. This is not true.

. - , . , .

Key.from_path:

k = Key.from_path('User', 'Boris', 'Address', 9876)

kind=User&name=Boris , kind=Address&name=9876 , . - .

App Engine , , , ergo . ​​ , , , n 2 ^ (n + 1) .

+6

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


All Articles