benoitc / benoitc/couchdbkit

Allow types contained by documents to serialize themselves

Open
#17 1 comment 0 reactions 0 assignees View on GitHub
improvment
Dominant language
Python
Stars
263
Forks
90
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.