from redisco import models
class Person(models.Model):
name = models.Attribute(required=True)
created_at = models.DateTimeField(auto_now_add=True)
fave_colors = models.ListField(str)
类里面支持的所有数据类型如下:
Model Attributes
Attribute
Stores unicode strings. If used for large bodies of text, turn indexing of this field off by setting indexed=True.
IntegerField
Stores an int. Ints are stringified using unicode() before saving to Redis.
Counter
An IntegerField that can only be accessed via Model.incr and Model.decr.
DateTimeField
Can store a DateTime object. Saved in the Redis store as a float.
DateField
Can store a Date object. Saved in Redis as a float.
FloatField
Can store floats.
BooleanField
Can store bools. Saved in Redis as 1's and 0's.
ReferenceField
可以引用其他的model.Model类,比如可以在一个通讯录类里增加一个字段它的类型是人物这个类他们都继承model.Model类但可以互相引用这样你就可以直接通过 通讯录.人物这样的方式调用(之后的文章会详细介绍)
ListField
列表类型,使用跟python的list一样可以将 python里的unicode, int, float和其他redisco.model类放进去
生成一个Person类的数据
>>person = Person(name="hupu")
因为name是必填字段所以必须要给