[Zope] Create subfolder at product creation

Dieter Maurer dieter@handshake.de
Wed, 3 Jul 2002 20:14:32 +0200


Chad Nantais writes:
 > I have a folderish Python product called "Customer".  When an instance of
 > this product is created, I want it to contain a folder called "Vehicles"
 > which is a normal OFS.Folder that will contain Vehicle objects owned by the
 > customer.  If I create a manage_afterAdd method in the Customer class, what
 > does it need to call to create a folder called "Vehicles"?  Or, if the
 > manage_afterAdd is not a good way to accomplish this, what is better?
I would do it in the constructor for your product instances.
It probably looks somehow like this:

   def addMyProduct(self,id):
     myInstance= MyProduct()
     myInstance._setId(id)
     self._setObject(id,myInstance)
     # you add here
     myInstance= getattr(self,id) # to acquisition wrap it
     childFolder= Folder()
     childFolder._setId('some_nice_id')
     myInstance._setObject('some_nice_id',childFolder)
     # here continues your previous code.
     ...


Dieter