Fields¶
Fields let you define your object’s properties and transform the values retrieved from the database, we support the following:
fields.Text
A simple text fieldfields.Hash
A hashed text using bcryptfields.Bool
A true/false valuefields.Integer
An integerfields.Float
A floating point valuefields.Datetime
A date and timefields.Location
A pair of latitude/longitude
Relation fields¶
We also provide fields for defining relationships with other models in a ORM-fashion
fields.SetRelation
Stored as a set of the related idsfields.SortedSetRelation
Stored as a sorteed set of the related ids, using a sotring keyfields.ForeignIdRelation
simply stores the string id of the related object
Indexes¶
Only Text fields are ready to be indexes
Creating your own fields¶
Simply subclass Field
or Relation
.
NORM fields follow an specific workflow to read/write from/to the redis database. Such workflow needs the following methods to be implemented (or inherited) for each field:
__init__
for field initialization, don’t forget to call the parent’s constructorinit
is called to parse a value given in the model’s constructorrecover
is called to parse a value retrieved from databaseprepare
is called to transform values or prepare them to be sent to databaseto_json
should return the json-friendly version of the valuevalidate
is called when doingModel.validate(data)
orobj.update(data)
Additionally, the following methods are needed for Relation
subclasses:
- save(value, pipeline[, commit=True])¶
persists this relationship to the database
- relate(obj, pipeline)¶
sets the given object as related to the one that owns this field
- delete(pipeline)¶
tells what to do when a model with relationships is deleted
- key()¶
returns a fully qualified redis key to this relationship
for subclasses of
SetRelation
, returns the list of related ids
- __contains__(obj)¶
is for subclasses of
SetRelation
and should tell wether or not the given object is in this relation.