开发者

Google App Engine - Adding a record only if it doesn't exist yet

In Google App Engine, consider the following datastore model:

class Update(db.Model):
    content = db.TextProperty()
    date = db.DateTimeProperty()
    source = db.StringProperty()

To add a new record, I do something like:

db.put(Update(content=开发者_开发知识库..., date=..., source=...))

How can I add a record to the datastore only if it doesn't exist yet? What is the most efficient way to do this?


db.Model.get_or_insert(key_name) lets you pass the key name of the object to get or insert (think of it like a primary key)

More information about key_name

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜