[Zope-dev] Referring to same interface using zope.schema.Object
    Jacob Holm 
    jh at improva.dk
       
    Fri Jul 22 07:41:32 EDT 2011
    
    
  
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
    
    
More information about the Zope-Dev
mailing list