peewee 需要支持mysql json 类型
一、基础model
class User(Model):
name = CharField(unique=True)
some_json_data = CharField()
requested_at = DateTimeField(default=datetime.now())
二、自定义字段 json 字段
class JSONField(TextField):
def db_value(self, value):
return json.dumps(value)
def python_value(self, value):
if value is not None:
return json.loads(value)
三、自定义字段 json 字段
class User(Model):
name = CharField(unique=True)
some_json_data = JSONField()
requested_at = DateTimeField(default=datetime.now())
定义一个JSONField自动执行 json 加载/转储的自定义类型
https://*.com/questions/40553790/peewee-orm-jsonfield-for-mysql
http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field