Fields¶
-
class
springfield.fields.
AdaptableTypeField
(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Field
that has a specific type and can be adapted to another type.
-
class
springfield.fields.
BooleanField
(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Field
that 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
Field
that can contain an ordered list of values matching a specificField
type.-
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]¶ Field
whose 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]¶ Field
with an email value
-
class
springfield.fields.
EntityField
(entity, *args, **kwargs)[source]¶ Field
that 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
Entity
class. Any specialization that needs to be done based on theEntity
class itself should be done here.Parameters: cls – An Entity
class.
-
-
class
springfield.fields.
FieldDescriptor
(name, field)[source]¶ A descriptor that handles setting and getting
Field
values on anEntity
.
-
class
springfield.fields.
FloatField
(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Field
that contains a float.
-
class
springfield.fields.
IdField
(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Field
that is used as the primary identifier for anEntity
TODO This should accept another Field type to contain the ID
-
class
springfield.fields.
IntField
(default=Empty, doc=None, *args, **kwargs)[source]¶ A
Field
that contains an int.
-
class
springfield.fields.
SlugField
(default=Empty, doc=None, *args, **kwargs)[source]¶ Field
whose 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.