When using Dexterity, can you combine simulated types with schema-driven types?

How to create a hybrid type (i.e. a type that supports the convenience of types controlled by the model, but uses the necessary schemes if possible)?

My most recent research has led me to model-oriented agility types as the most convenient approach to agility development. I follow this article: http://developer.plone.org/reference_manuals/external/plone.app.dexterity/model-driven-types.html as opposed to the schema types described here: http://developer.plone.org/ reference_manuals / external / plone.app.dexterity / schema-driven-types.html .

The hybrid approach came about because of a problem that I ran into links that are still not predictably using simulated types. I expect schematic definitions to give me finer-grained control in such situations.

+4
source share
1 answer

You can create a diagram 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 as in the model.

The model loads at the end of the ZCML configuration phase. This means that there is a caveat: You cannot refer to a field from a model in the module area anywhere. For example, registering the default value with the @ form.default_value decorator (IMySchema ['foo']) will not work, since the field has not yet been loaded while the decorator is executing during import.

+6
source

Source: https://habr.com/ru/post/1490521/


All Articles