The fields module contains a list of Field classes for model’s definition.
The example below shows the most common fields and builtin validations:
class Token(Model): key = String() secret = String() class User(Model): login = String(required=True) name = String() role = String(choices=['admin', 'moderator', 'user']) email = Email(required=True) token = Embedded(Token, required=True) is_active = Boolean(default=False)
- class fields.Embedded(model, *args, **kwargs)¶
- class fields.Field(*validators, **kwargs)¶
This is the base class for all booby.fields. This class can also be used as field in any models.Model declaration.
- default –
This field default‘s value.
If passed a callable object then uses its return value as the field’s default. This is particularly useful when working with mutable objects.
If default is a callable it can optionaly receive the owner model instance as its first positional argument.
- required – If True this field value should not be None.
- choices – A list of values where this field value should be in.
- name – Specify an alternate key name to use when decoding and encoding.
- read_only – If True, the value is treated normally in decoding but omitted during encoding.
- *validators – A list of field validators as positional arguments.
- default –