[Zope3-dev] Circular references between interfaces

Peter Mayne PeterMayne at ap.spherion.com
Fri Oct 8 00:04:18 EDT 2004


I'm writing an IMDB application, to show that Z3 can run its own copy of 
  the Internet Movie Database. A few questions are coming up along the way.

My schema has an IActor with a List containing value_type=IMovie. IMovie 
has a List of value_type=IActorRef, and IActorRef in turn has an IActor 
attribute. This creates a circular reference.

Currently I have in my interfaces.py (omitting irrelevant fields):

class IActor(Interface):
     '''Actor definition.'''

class IActorRef(Interface):
     '''A reference to an IActor from an IMovie.'''

     actor = Object(
         title = u'Actor',
         description = u'The actor.',
         required = True,
         default = None,
         schema = IActor)

class IMovie(Interface):
     '''Movie definition.'''

     cast = List(
         title = u'Cast',
         description = u'Cast list.',
         value_type = Object(IActorRef, title = u'Actor reference'),
         default = [],
         required = False)

IActor.movies = List(
         title = u'Movies',
         description = u'Movies this actor has been in.',
         value_type = Object(IMovie, title = u'Movie reference'),
         default = [],
         required = False)

but when I attempt to access the IActor.movies attribute in my template, 
I get "ForbiddenAttribute: ('movies', <imdb.actor.Actor object at 
0x416b72ac>)".

I've also tried the following implementation of Actor:

class Actor(Persistent, Contained):
     implements(IActor, IMovieFolderContained)

     def getMovies(self):
         return getattr(self, '_movies', [])

     def setMovies(self, movies):
         self._movies = movies

     movies = property(getMovies, setMovies)

to handle the List, but the same thing happens. (The same thing seems to 
have worked for my Movie implementation, though.)

Should I make my schema more relational and remove the circular 
reference, or is there a right way to do this?

Thanks.

PJDM
-- 
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"You're given the form, but you have to write the sonnet yourself.
What you say is completely up to you." - Mrs. Whatsit



More information about the Zope3-dev mailing list