Hi,
1. I was following the examples for DictField in
http://packages.python.org/CouchDB/mapping.html
2. I wrote a small script to prevent me from typing things over and
over again, it looks like this:
-------------------------------------------
BEGIN--------------------------------------------------
from couchdb import Server, Document
from couchdb.mapping import TextField, IntegerField, DateTimeField,\
DictField, ListField, Mapping
class Post(Document):
name = TextField()
content = TextField()
author = DictField(Mapping.build(
name = TextField(),
email = TextField()
))
extra = DictField()
def create_server():
server = Server('http://xxxxxxxx:ABCDEFG@localhost:5984')
if 'python-tests' in server:
del server['python-tests']
db = server.create('python-tests')
return db
-------------------------------------------
END-------------------------------------------------
3. I wanted to test to see if I could add additional attributes/keys
to a Document mapping even after it has already been defined. I
created a new Post like such (age is the newly added attribute):
>>> post = Post(
... title='Foo bar',
... author=dict(name='John Doe',
... email='
jo...@doe.com'),
... extra=dict(foo='bar'),
... age=42
... )
However, when I try to save the document into the db using
post.store(db), it errors out saying something like this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Post' object has no attribute 'store'
And if I try to access the variable "post", it prints the following
error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.7-intel/egg/couchdb/client.py", line
933, in __repr__
File "build/bdist.macosx-10.7-intel/egg/couchdb/client.py", line
943, in id
KeyError: '_id'
4. Can someone please help me out, I'm really lost here. The strange
part about this is that, I went through these examples earlier in the
day and everything seemed to work.
5. Finally, for those curious, I am using CouchDB version 1.1.1 and
couchdb-python version 0.9a (the one from Mercurial, as I heard the
0.8 one had some bugs with ListField).
Thanks in advance.
Regards,
Mark Huang