Reputation: 2472
In the following example, I want objects implementing IParentInterface to be required to supply a mycollection attribute that is a list of objects implementing IChildInterface.
from zope.schema import Text, List
from zope.interface import Interface
class IChildInterface(Interface):
someField = Text()
class IParentInterface(Interface):
mycollection = List(value_type=IChildInterface)
Is there a straightforward way to do this, or would I need to use invariants?
Upvotes: 2
Views: 114
Reputation: 4496
This should work:
from zope.schema import Text, List, Object
from zope.interface import Interface
class IChildInterface(Interface):
someField = Text()
class IParentInterface(Interface):
mycollection = List(value_type=Object(title=u'Child',
schema=IChildInterface))
Upvotes: 4