[Zope] Accessing parent's methods/attrs from a child object

Dieter Maurer dieter@handshake.de
Thu, 10 Apr 2003 20:01:07 +0200


Chad Nantais wrote at 2003-4-9 14:49 -0700:
 > I have a container objectManager called 'Vehicle'.
 > 'Repair', which is a simpleItem, is stored inside a Vehicle instance.
 > 
 > When a Repair is created or edited, it should update the containing 
 > Vehicle's odometer reading by calling updateOdometer(newreading) on the 
 > Vehicle it is belongs to.  I tried adding 
 > self.aq_parent.updateOdometer(newReading) to Repair.py's update method.

I would directly use "self.updateOdometer" and let acquisition find
the correct object.

You need to worry about "aq_parent" (and friends) only,
when acquisition does not find the correct method
(e.g. when "self" defined the method, too).

To get the container of an object ("self"), you use

   self.aq_inner.aq_parent


"self.aq_parent" is usually *not* what you want.


Dieter