Fields¶
Fields let you define your object’s properties and transform the values retrieved from the database, we support the following:
fields.TextA simple text fieldfields.HashA hashed text using bcryptfields.BoolA true/false valuefields.IntegerAn integerfields.FloatA floating point valuefields.DatetimeA date and timefields.LocationA pair of latitude/longitude
Relation fields¶
We also provide fields for defining relationships with other models in a ORM-fashion
fields.SetRelationStored as a set of the related idsfields.SortedSetRelationStored as a sorteed set of the related ids, using a sotring keyfields.ForeignIdRelationsimply 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 constructorinitis called to parse a value given in the model’s constructorrecoveris called to parse a value retrieved from databaseprepareis called to transform values or prepare them to be sent to databaseto_jsonshould return the json-friendly version of the valuevalidateis 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
-
fill()¶ is called when you need to know the relationships for a model. Usually via the proxy object.
-
__contains__(obj)¶ is for subclasses of
SetRelationand should tell wether or not the given object is in this relation. Usually called via the proxy object.