The extras-mongoengine package provides the following extra fields for use on
MongoEngine Documents:
TimedeltaField- a field for storingdatetime.timedeltavalues.LowerStringField- a string field that transforms input strings to lowercase.LowerEmailField– aLowerStringFieldthat also check if the string is valid according to the MongoEngine email regex (EmailField.EMAIL_REGEX).IntEnumField- a field for storing Python 3.4 (or later) Enum values where the values in the enum areints.StringEnumField- a field for storing Python 3.4 (or later) Enum values where the values in the enum arestrs.
To use the IntEnumField and StringEnumField fields on Python 2.* or Python <3.4
you have to install the enum34 package.
from mongoengine import Document
from enum import Enum
from extras_mongoengine.fields import StringEnumField
class BeverageType(Enum):
Tea = 'TEA'
Coffee = 'COFFEE'
class Beverage(Document):
beverage_type = StringEnumField(BeverageType, default=BeverageType.Tea)