class User(Model): name = CharField(unique=True) some_json_data = CharField() requested_at = DateTimeField(default=datetime.now())
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)
class User(Model): name = CharField(unique=True) some_json_data = JSONField() requested_at = DateTimeField(default=datetime.now())
定义一个JSONField自动执行 json 加载/转储的自定义类型
https://stackoverflow.com/questions/40553790/peewee-orm-jsonfield-for-mysql
http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field