primary key in google appengine datastore
from google.appengine.ext import db
from datetime import date
class Test(db.Model):
title=db.StringProperty(required=True)
tags=db.StringListProperty(required=True)
a print on the Test type of object shows
Test(key_id=1, title='ashu_saved', tags=['db'])
but the key_id attribute is is not accesible by title.key_id
.also test.pk
returns u'agRibG9nchILEgxhc2lzYWlkX3Rlc3QYAQw'
is there a way to obtain nicely looking integer primary keys that i can use in the urls, from the model objects in google-appengine?
Try with:
yourkey = test.key().id()
and to get your value back:
Test.get_by_id(ids = yourkey)
It is invalid solution since all record have id() the best is this:
key = entity.key()
Model.get(key)
Record can have id() or name() but must have key().
Even all your record has id() it is still wrong since entity is addressed by ApplicationId, NamespaceId, ParentModel, Model and than id or key. PRIMARY key is all that fields.
It mean you can have many entities with same id() if you use namespaces or use parent to keep transactions consistent - try avoid id() use if you are not sure about it.
链接地址: http://www.djcxy.com/p/57822.html上一篇: Appengine数据存储的优势
下一篇: 谷歌appengine数据存储的主键