Allow types contained by documents to serialize themselves

未关闭
#17 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
database

调研方向

首先追踪 DictProperty 值的序列化方式,以及 ALLOWED_TYPES 在哪里拒绝 Animal。查看所请求的 to_json 和 from_json 契约,以及 MyDoc.animals 示例。完成的标准是:无需将 Animal 设为 CouchDB 模型,包含的自定义对象即可通过这些方法进行序列化和反序列化,并且不再引发现有异常。

由索引模型根据 Issue 内容生成。

描述

improvment

class MyDoc(Document):
animals = DictProperty()

class Animal(object):
def init():
self.name = "Joe"
self.age = 14

def to_json():
"""Code to serialize to json"""
def from_json:
"""Code to load from json"""
...

The animal class intentional is not a couchdb model and we don't want to tie it to couchdb. What we want is being able to have it automatically serialized and deserialized by couchdbkit calling these methods it implements. In this case the contract would be to_json and from_json.

doc = MyDoc()
doc.animals['horsea'] = Animal(...)
doc.animals['horseb'] = Animal(...)
doc.save()

Currently this will raise an exception saying that Animal is not in ALLOWED_TYPES.

主要语言
Python
星标
261
派生
90
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

benoitc/couchdbkit 的其他 Issue

查看 benoitc/couchdbkit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。