Fields

by Martin Aspeli last modified Oct 10, 2009 03:12 PM

The standard schema fields

The following tables shows the most common field types for use in Dexterity schemata. See the documentation on creating schemata for information about how to use these.

Field properties

Fields are initialised with properties passed in their constructors. To avoid having to repeat the available properties for each field, we'll list them once here, grouped into the interfaces that describe them. You'll see those interfaces again in the tables below that describe the various field types. Refer to the table below to see what properties a particular interface implies.

InterfacePropertyTypeDescription
IFieldtitleunicodeThe title of the field. Used in the widget.
 descriptionunicodeA description for the field. Used in the widget. 
 requiredboolWhether or not the field is required. Used for form validation. The default is True
 readonlyboolWhether or not the field is read-only. Default is False
 defaultThe default value for the field. Used in forms and sometimes as a fallback value. Must be a valid value for the field if set. The default is None.
 missing_valueA value that represents "this field is not set". Used by form validation. Defaults to None. For lists and tuples, it is sometimes useful to set this to an empty list/tuple.
IMinMaxLenmin_lengthintThe minimum required length. Used for string fields. Default is 0.
 max_lengthintThe maximum allowed length. Used for string fields. Default is None (no check).
IMinMaxmin
The minimum allowed value. Must be a valid value for the field, e.g. for an Int field this should be an integer. Default is None (no check).
 max
The maximum allowed value. Must be a valid value for the field, e.g. for an Int field this should be an integer. Default is None (no check).
ICollectionvalue_type Another Field instance that describes the allowable values in a list, tuple or other collection. Must be set for any collection field. One common usage is to set this to a Choice, to model a multi-selection field with a vocabulary.
 uniqueboolWhether or not values in the collection must be unique. Usually not set directly - use a Set or Frozenset to guarantee uniqueness in an efficient way. 
IDictkey_type Another Field instance that describes the allowable keys in a dictionary. Similar to the value_type of a collection. Must be set.
 value_type Another Field instance that describes the allowable values in a dictionary. Similar to the value_type of a collection. Must be set.
IObjectschemaInterfaceAn interface that must be provided by any object stored in this field.
IRichTextdefault_mime_typestrDefault MIME type for the input text of a rich text field. Defaults to text/html.
 output_mime_typestrDefault output MIME type for the transformed value of a rich text field. Defaults to text/x-html-safe. There must be a transformation chain in the portal_transforms tool that can transform from the input value to the output value for the output property of the RichValue object to contain a value.
allowed_mime_typestupleA list of allowed input MIME types. The default is None, in which case the site-wide settings (from the Markup control panel) will be used. 

Field types

The following tables describe the most commonly used field types, grouped by the module from which they can be imported.

Fields in zope.schema

NameTypeDescriptionProperties
ChoiceN/AUsed to model selection from a voacabulary, which must be supplied. Often used as the value_type of a selection field. The value type is the value of the terms in the vocabulary.See vocabularies
Bytesstr Used for binary data. IField, IMinMaxLen 
ASCII str ASCII text (multi-line) IField, IMinMaxLen
BytesLinestr A single line of binary data, i.e. a Bytes with newlines disallowed IField, IMinMaxLen
ASCIILinestrA single line of ASCII textIField, IMinMaxLen
TextunicodeUnicode text (multi-line). Often used with a WYSIWYG widget, although the default is a text area.IField, IMinMaxLen
TextLineunicodeA single line of Unicode textIField, IMinMaxLen
BoolboolTrue or FalseIField 
Intint, longAn integer number. Both ints and longs are allowed. IField, IMinMax
FloatfloatA floating point number.IField, IMinMax
TupletupleA tuple (non-mutable)IField, ICollection, IMinMaxLen
Listlist A listIField, ICollection, IMinMaxLen
Setset A setIField, ICollection, IMinMaxLen
FrozensetfrozensetA frozenset (non-mutable)IField, ICollection, IMinMaxLen
PasswordunicodeStores a simple string, but implies a password widget. IField, IMinMaxLen
Dictdict Stores a dictionary. Both key_type and value_type must be set to fields.IField, IMinMaxLen, IDict
DatetimedatetimeStores a Python datetime (not a Zope 2 DateTime)IField, IMinMax 
Datedate Stores a python date IField, IMinMax 
TimedeltatimedeltaStores a python timedelta IField, IMinMax 
SourceTextunicodeA textfield intended to store source text (e.g. HTML or Python code) IField, IMinMaxLen 
ObjectN/AStores a Python object that conforms to the interface given as the schema. There is no standard widget for this. IField, IObject 
URIstrA URI (URL) string IField, MinMaxLen 
IdstrA unique identifier - either a URI or a dotted name. IField, IMinMaxLen 
DottedNamestrA dotted name string. IField, IMinMaxLen 
InterfaceFieldInterfaceA Zope interface. IField
DecimalDecimalStores a Python Decimal. Requires version 3.4 or later of zope.schema. Not available by default in Zope 2.10. IField, IMinMax 

Fields in plone.namedfile.field

See plone.namedfile and plone.formwidget.namedfile for more details.

NameTypeDescriptionProperties
NamedFileNamedFileA binary uploaded file. Normally used with the widget from plone.formwidget.namedfile.IField
NamedImage NamedImageA binary uploaded image. Normally used with the widget from plone.formwidget.namedfileIField 
NamedBlobFile NamedBlobFileA binary uploaded file stored as a ZODB BLOB. Requires the [blobs] extra to plone.namedfile. Otherwise identical to NamedFileIField 
NamedBlobImageNamedBlobImageA binary uploaded image stored as a ZODB BLOB. Requires the [blobs] extra to plone.namedfile. Otherwise identical to NamedImage.IField

Fields in z3c.relationfield.schema

See z3c.relationfield for more details

NameTypeDescriptionProperties
RelationRelationValueStores a single RelationValue.IField
RelationListlistA List field that defaults to Relation as the value typeSee List
RelationChoiceRelationValueA Choice field intended to store RelationValue'sSee Choice

Fields in plone.app.textfield

See plone.app.textfield for more details

NameTypeDescriptionProperties
RichTextRichTextValueStores a RichTextValue, which encapsulates a raw text value, the source MIME type, and a cached copy of the raw text transformed to the default output MIME type.IField, IRichText