Re: [Zope-dev] Referring to same interface using zope.schema.Object

Jacob Holm <[email protected]>
Newsgroups gmane.comp.web.zope.bluebream,gmane.comp.web.zope.devel
Message-ID <[email protected]>
On 2011-07-22 13:26, Brian Sutherland wrote:
> This would be my first guess:
> 
>     class INode(Interface):
>         pass
>      
>     INode.parent = Object(
>             title=u"Parent node",
>             schema=INode
>             )
> 
>     INode.children = List(
>             title=u'Child nodes',
>             value_type=Object(schema=INode)
>             )
> 


And that guess would be wrong.  You can't add fields to an existing
schema like that (not sure if you can in other ways).  You *can* change
an existing field however, so a working solution would be:

    class INode(Interface):

        parent = Object(
            title = u'Parent node',
            schema = Interface, # set to INode later
            )

        children = List(
            title = u'Child nodes',
            value_type = Object(schema=Interface), # set to INode later
            )

    INode['parent'].schema = INode
    INode['children'].value_type.schema = INode


Hope this helps

  - Jacob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.