Fields¶
-
class
springfield.fields.AdaptableTypeField(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Fieldthat has a specific type and can be adapted to another type.
-
class
springfield.fields.BooleanField(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Fieldthat contains a bool.-
adapt(value)[source]¶ Adapt value to a bool.
Parameters: value – A boolean-like value.
A float, int, or long will be converted to:
- True if equal to 1
- False if equal to 0
String values will be converted to (case-insensitive):
- True if equal to “yes”, “true”, “1”, or “on”
- False if equal to “no”, “false”, “0”, or “off”
-
-
class
springfield.fields.CollectionField(field, *args, **kwargs)[source]¶ A
Fieldthat can contain an ordered list of values matching a specificFieldtype.-
adapt(value)[source]¶ Adapt all values of an iterable to the
CollectionField‘s field type.
-
flatten(value)[source]¶ Convert all values of an iterable to the
CollectionField‘s field type’s native Python type.
-
jsonify(value)[source]¶ Convert all values of an iterable to the
CollectionField‘s field type’s JSON type.
-
-
class
springfield.fields.DateTimeField(default=Empty, doc=None, *args, **kwargs)[source]¶ Fieldwhose value is a Python datetime.datetime-
adapt(value)[source]¶ Adapt value to a datetime.datetime instance.
Parameters: value – A date-like value. RFC3339 formatted date-strings are supported.
If dateutil is installed, dateutil.parser.parse is used which supports many date formats.
-
type¶ alias of
datetime
-
-
class
springfield.fields.EmailField(default=Empty, doc=None, *args, **kwargs)[source]¶ Fieldwith an email value
-
class
springfield.fields.EntityField(entity, *args, **kwargs)[source]¶ Fieldthat can contain anEntity
-
class
springfield.fields.Field(default=Empty, doc=None, *args, **kwargs)[source]¶ A field
-
adapt(value)[source]¶ Convert the value from the input type to the expected type if needed.
Returns: The adapted value
-
flatten(value)[source]¶ Get the value as a basic Python type
Parameters: value – An Entity‘s value for thisField
-
init(cls)[source]¶ Initialize the field for its owner
Entityclass. Any specialization that needs to be done based on theEntityclass itself should be done here.Parameters: cls – An Entityclass.
-
-
class
springfield.fields.FieldDescriptor(name, field)[source]¶ A descriptor that handles setting and getting
Fieldvalues on anEntity.
-
class
springfield.fields.FloatField(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Fieldthat contains a float.
-
class
springfield.fields.IdField(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Fieldthat is used as the primary identifier for anEntityTODO This should accept another Field type to contain the ID
-
class
springfield.fields.IntField(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Fieldthat contains an int.
-
class
springfield.fields.SlugField(default=Empty, doc=None, *args, **kwargs)[source]¶ Fieldwhose value is a slugified string.A slug is a string converted to lowercase with whitespace replace with a “-” and non-ascii chars converted to their ascii equivalents.