Phillip B Oldham wrote:
> Hi all. I'm playing with standalone ZODB at the moment trying to get a
> better understanding of its use in applications. I come from a
> PHP/MySQL background, and I'm taking my first steps with Python at the
> same time.
Heh, and just when people are moving more and more to ORMs like
> One of the things I'm not understanding about ZODB is assigning
> incremental IDs to objects.
How important is it that they're strictly incremental?
If it is, you may want to look at the BTrees.Length module.
You can treat a Length a bit like a relational database sequence,
provided you keep incrementing each time you use the Length's value as
> For instance, if I were to be writing a
> support-ticket system I'd want to give each ticket a unique number,
> but one that's "human-useable" (otherwise you could just use a UUID -
> try giving one of those over the phone!).
Well, the UUID you'd be thinking of would best be just the ZODB OID ;-)
> class Ticket(Persistence):
> def __init__(self):
> self.id = '' # How do I add a new incremental ID here?
> # and later on in the app
> tkt = Ticket()
> dbroot[?????] = tkt
Well, if it was just plain ZODB, I'd do it as follows:
from persistent import Persistent
from IOBTrees import IOTree
from BTrees.Length import Length
self.next_id = Length()
id = self.next_id()
t = self[id] = Ticket()
It's very rare that a ticket needs to know its own id. If it does, it
should ask its container.
Simplistix - Content Management, Zope & Python Consulting
Zope maillist - Zope@zope.org
** No cross posts or HTML encoding! **
(Related lists -