[Zope] calling methods

Casey Duncan c.duncan@nlada.org
Thu, 18 Oct 2001 09:02:33 -0400


On Thursday 18 October 2001 04:59 am, Antonio Beamud Montero allegedly wrote:
[snip]
> A is Folder with a lot of object instances.
> from one of this instances I want to had a variable of references to
> objects in the same folder, but I don't know how to do this.
>
> Something like this:
>
> Class A(Folder):
> ...
>
> Class x(Implicit, Persistent, PropertyManager, RoleManager, Item):
> 	....
> 	__init__(self, id, title):
> 	self.myfriends = []
> 	def list_Posible_Friends(self):
> 	  """ Here I want to know what objects has instantiated my container"""
>
>           posible_list = self.objectValues()
>
> #######################
> This action doesn't works like I want to works...
> #######################
>
> 	 def addFriend(self, Ref):
> 	    list.append(Ref)
>
> How I can do this

You can use aq_parent to get the container as in:

def list_Possible_Friends(self):
    possible_list = self.aq_parent.objectValues()

However I would caution against storing references to these objects in your x 
instances (like your code in addFriend implies). This creates a circular 
reference such that if the object is deleted from thecontainer, it still 
exists in your instance. This makes it hard to really get rid of an object.

This adds another layer of bookkeeping to your application unless you don't 
care about "leaking" objects this way.

hth,
/---------------------------------------------------\
  Casey Duncan, Sr. Web Developer
  National Legal Aid and Defender Association
  c.duncan@nlada.org
\---------------------------------------------------/