开发者

Is there a primary key concept in ZODB for objects

开发者 https://www.devze.com 2022-12-24 23:37 出处:网络
I wanted to know if we can have a unique identifier for all objects that are stored i开发者_C百科n ZODBEach object stored in the ZODB does have a unique ID, accessible as its _p_oid attribute after th

I wanted to know if we can have a unique identifier for all objects that are stored i开发者_C百科n ZODB


Each object stored in the ZODB does have a unique ID, accessible as its _p_oid attribute after the object has been registered:

>>> obj._p_oid

The usual caveats about primary keys apply -- if you need a unique identifier that you can continue to use even if you need to export your objects to a different database, you're better off using a uuid that you manage yourself. Python has a uuid module (in the stdlib as of Python 2.6) which can generate uuids.

0

精彩评论

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

关注公众号