flywheel.fields package¶
Submodules¶
Module contents¶
Field declarations for models
-
class
flywheel.fields.
Composite
(*args, **kwargs)[source]¶ Bases:
flywheel.fields.Field
A field that is composed of multiple other fields
Parameters: - *fields : list
List of names of fields that compose this composite field
- hash_key : bool, optional
This key is a DynamoDB hash key (default False)
- range_key : bool, optional
This key is a DynamoDB range key (default False)
- index : str, optional
If present, create a local secondary index on this field with this as the name.
- data_type : str, optional
The dynamo data type. Valid values are (NUMBER, STRING, BINARY, NUMBER_SET, STRING_SET, BINARY_SET, dict, list, bool, str, unicode, int, float, set, datetime, date, Decimal) (default unicode)
- coerce : bool, optional
Attempt to coerce the value if it’s the incorrect type (default False)
- check : callable, optional
A function that takes the value and returns True if the value is valid (default None)
- merge : callable, optional
The function that merges the subfields together. By default it simply joins them with a ‘:’.
-
class
flywheel.fields.
Field
(hash_key=False, range_key=False, index=None, data_type=<object object>, type=<type 'unicode'>, coerce=False, check=None, nullable=True, default=<object object>)[source]¶ Bases:
object
Declarative way to specify model fields
Parameters: - hash_key : bool, optional
This key is a DynamoDB hash key (default False)
- range_key : bool, optional
This key is a DynamoDB range key (default False)
- index : str, optional
If present, create a local secondary index on this field with this as the name.
- type : object, optional
The field data type. You may use int, unicode, set, etc. or you may pass in an instance of
TypeDefinition
(default unicode)- coerce : bool, optional
Attempt to coerce the value if it’s the incorrect type (default False)
- check : callable or list, optional
A function that takes the value and returns True if the value is valid. May also be a list of such functions. (default None)
- nullable : bool, optional
If false, will add a check (above) to ensure the value is not null (default True).
- default : object, optional
The default value for this field that will be set when creating a model (default None, except for
set
data types which default to set())
Notes
Field(index='my-index')
Is shorthand for:
Field().all_index('my-index')
Attributes: - name : str
The name of the attribute on the model
- model : class
The
Model
this field is attached to- composite : bool
True if this is a composite field
-
all_index
(name)[source]¶ Index this field and project all attributes
Parameters: - name : str
The name of the index
-
between_
(low, high)[source]¶ Create a query condition that this field must be between two values (inclusive)
-
betwixt_
(low, high)[source]¶ Poetic version of
between_()
-
can_resolve
(fields)[source]¶ Check if the provided fields are enough to fully resolve this field
Parameters: - fields : list or set
Returns: - needed : set
Set of the subfields needed to resolve this field. If empty, then it cannot be resolved.
-
include_index
(name, includes=None)[source]¶ Index this field and project selected attributes
Parameters: - name : str
The name of the index
- includes : list, optional
List of non-key attributes to project into this index
-
keys_index
(name)[source]¶ Index this field and project all key attributes
Parameters: - name : str
The name of the index
-
validate
(obj)[source]¶ Run the validation checks for this field on a model object.
Parameters: - obj :
Model
Raises: - err :
ValueError
Raised if any of the checks fail.
- obj :