Question

How do I create a hybrid type (i.e. a type that keeps the convenience of model-driven types but takes advantage of schema-driven types on an as-needed basis)?

My most recent explorations have led me to model-driven dexterity types as the most convenient approach for dexterity development. I've been following this article: http://developer.plone.org/reference_manuals/external/plone.app.dexterity/model-driven-types.html in contrast to schema driven types documented here: http://developer.plone.org/reference_manuals/external/plone.app.dexterity/schema-driven-types.html.

The hybrid approach arose from a problem I've come upon with references, which so far do not behave predictably using model-driven types. I expect that schema-driven definitions will give me more fine-grained control in situations like this.

Était-ce utile?

La solution

You can create a schema based on a model:

from plone.supermodel import model

class IMySchema(model.Schema):
    model.load('path/to/model.xml')

Any fields defined in the Python schema will take precedence over those with the same name defined in the model.

The model is loaded at the end of the ZCML configuration phase. This means there's a caveat: You can't refer to a field from the model at module scope anywhere. For example, registering a default value using the @form.default_value(IMySchema['foo']) decorator will not work, because the field hasn't been loaded yet at the time when the decorator executes at import time.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top