Package couchdb :: Module schema :: Class DictField

Class DictField

object --+    
         |    
     Field --+
             |
            DictField

Field type for nested dictionaries.

>>> from couchdb import Server
>>> server = Server('http://localhost:5984/')
>>> db = server.create('python-tests')
>>> class Post(Document):
...     title = TextField()
...     content = TextField()
...     author = DictField(Schema.build(
...         name = TextField(),
...         email = TextField()
...     ))
...     extra = DictField()
>>> post = Post(
...     title='Foo bar',
...     author=dict(name='John Doe',
...                 email='john@doe.com'),
...     extra=dict(foo='bar'),
... )
>>> post.store(db) #doctest: +ELLIPSIS
<Post ...>
>>> post = Post.load(db, post.id)
>>> post.author.name
u'John Doe'
>>> post.author.email
u'john@doe.com'
>>> post.extra
{'foo': 'bar'}
>>> del server['python-tests']
Instance Methods
 
__init__(self, schema=None, name=None, default=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Inherited from Field: __get__, __set__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, schema=None, name=None, default=None)
(Constructor)

 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)