nanomongo.field

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

Instances of this class is used to define field types and automatically create validators:

field_name = Field(str, default='cheeseburger')
foo = Field(datetime, auto_update=True)
bar = Field(list, required=False)
__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)
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.