I have an embedded document class Post and a father-class Thread.
class Thread(Document):
...
posts = ListField(EmbeddedDocumentField("Post"))
class Post(EmbeddedDocument):
attribute = StringField()
...
I want to create a new post and add it to my ListField in the Thread class.
My code looks like this:
post = Post()
post.attribute = "noodle"
post.save()
thread.posts.append(post)
thread.save()
But I get the following error message:
“‘Post’ object has no attribute ‘save'”
If I skip the post.save() an empty Post object is appended to my Thread.
Any ideas?
Your code looks fine – are you sure you don’t have other thread objects? Heres a test case proving your code (without the post.save() step). What version do you have installed?