class nanomongo.field.Field(*args, **kwargs)[source]

Instances of this class is used to define field types and automatically create validators. Note that a Field definition has no value added:

field_name = Field(str, default='cheeseburger')
foo = Field(datetime, auto_update=True)
bar = Field(list, required=False)
classmethod check_kwargs(kwargs, data_type)[source]

Check keyword arguments & their values given to Field constructor such as default, required ...

generate_validator(t, **kwargs)[source]

Generates and returns validator function (value_to_check, field_name=''). field_name kwarg is optional, used for better error reporting.

Field.__init__(*args, **kwargs)[source]

Field kwargs are checked for correctness and field validator is set, along with other attributes such as required and auto_update

Keyword Arguments:
  • default: default field value, must pass type check, can be a callable
  • required: if True field must exist and not be None (default: True)
  • auto_update: set value to datetime.utcnow() before inserts/saves; only valid for datetime fields (default: False)