Model-driven types

In the previous section, we defined two types by using Zope schema. In this section, we’re going to define a type’s fields using an XML model file.

The great advantage of using a model file is that we can prototype the content type in Dexterity’s through-the-web field editor, then export the XML model file for incorporation into our package.

XML may be used to do pretty much anything you could do via Zope schema. Many users not already schooled in Zope schema will find this by far the easiest and fastest way to create Dexterity content types.

Setting the field model

Create an example/conference/models directory. In it, add a presenter.xml file with the contents:

<model xmlns:form=""
    <field name="name" type="zope.schema.TextLine">
    <field name="description" type="zope.schema.Text">
      <title>A short summary</title>
    <field name="bio" type="">
    <field name="photo" type="plone.namedfile.field.NamedBlobImage">
      <description>Please upload an image.</description>

The XML name spaces we use are described in the Dexterity XML reference section.

Now, open the that we created in the last section (a copy of our original Delete the field declarations from the IPresenter class and edit to read:

from example.conference import MessageFactory as _
from plone.supermodel import model
from zope import schema

class IPresenter(model.Schema):

    """Schema for Conference Presenter content type."""


Note the model.load directive. This will automatically load our model file to provide the content type field schema.

Setting Factory Type Information

This part of the process is identical to what we explained for schema-driven type.

Look in the types.xml file in your packages example/conference/profiles/default directory. It should now contain:

<object name="portal_types">
  <object name="Program" meta_type="Dexterity FTI" />
  <object name="Session" meta_type="Dexterity FTI" />
  <object name="Presenter" meta_type="Dexterity FTI" />

For the Presenter type, we have example.conference.presenter.xml:

<?xml version="1.0"?>
<object name="example.conference.presenter" meta_type="Dexterity FTI"

  <!-- Basic metadata -->
  <property name="title" i18n:translate="">Presenter</property>
  <property name="description" i18n:translate="">Conference Presenter</property>
  <property name="icon_expr">string:${portal_url}/document_icon.png</property>
  <property name="factory">Presenter</property>
  <property name="global_allow">True</property>
  <property name="filter_content_types">True</property>
  <property name="allowed_content_types" />
  <property name="allow_discussion">False</property>

  <!-- schema and class used for content items -->
  <property name="schema">example.conference.presenter.IPresenter</property>
  <property name="klass">plone.dexterity.content.Item</property>

  <!-- ... -->


Note that this is addable anywhere.