[Zope] Creating attributes in ZClass instances

Dieter Maurer dieter@handshake.de
Mon, 18 Dec 2000 23:07:24 +0100 (CET)


David Bustos writes:
 > I have a ZClass named Event.  Event objects need to keep a list of
 > people signed up for them, so they had a lines property named 'people'.
 > But lines properties have odd semantics, and I want to store arbitrary
 > objects rather than strings (i.e. it shouldn't be edited through the web
 > like a lines property is).  So I would like for the 'people' attributes
 > of Event objects to be regular Python lists.
I would make the class folder-like and add the people as people
ZInstances.

If you dislike only the editing through the web, then you
are not obliged to make it available.

 > It seems that I should create this attribute in the Event_add
 > constructor in my Product.  But how do I do that?
It is not forseen, that you add a list attribute to an object.
However, in Python, you could do it.

Be careful, however! There are several caveats that may make
it into a nightmare. One aspect (there may be more):

  The ZODB stores objects without (acquisition) context.
  Usually, the acquisition object is inherited from
  the parent object.
  However, lists, dictionaries etc. do not have an
  acquisition context. They can not inherit it to their
  components.
  Thus, if you access "list[i]", the resulting object
  does not have an acquisition context (if the list
  directly came from the ZODB) and the use of the resulting object
  is restricted.


Dieter