Accessing parent's methods/attrs from a child object
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. <code> def update(self, number=None, date=None, odometer=None, REQUEST=None): ''' Update repair properties ''' if number is not None: self._number = number if date is not None: try: self._date = date.year + '-' + date.month + '-' + date.day except: self._date = date if odometer is not None: self._odometer = int(odometer) self.aq_parent.updateOdometer(self._odometer) </code> The result was an attribute error (updateOdometer). Am I misusing aq_parent in this context? Basically, I need to know how to access methods and attributes of the parent object from within a child class. Thanks in advance. Chad
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
participants (2)
-
Chad Nantais -
Dieter Maurer