Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:42:43+00:00 2026-06-09T04:42:43+00:00

I have an embedded document class Post and a father-class Thread . class Thread(Document):

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:42:44+00:00Added an answer on June 9, 2026 at 4:42 am

    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?

    import unittest
    from mongoengine import *
    
    
    class Test(unittest.TestCase):
    
        def setUp(self):
            conn = connect(db='mongoenginetest')
    
        def test_something(self):
    
            class Thread(Document):
                posts = ListField(EmbeddedDocumentField("Post"))
    
            class Post(EmbeddedDocument):
                attribute = StringField()
    
            Thread.drop_collection()
    
            thread = Thread()
            post = Post()
            post.attribute = "Hello"
    
            thread.posts.append(post)
            thread.save()
    
            thread = Thread.objects.first()
            self.assertEqual(1, len(thread.posts))
            self.assertEqual("Hello", thread.posts[0].attribute)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document and a embedded document using MongoEngine class Sub(EmbeddedDocument): Id =
I have products as an embedded document inside the category class as shown below:
I have a Post document that has embedded tags. Sometimes I display only the
If I have: class Post include MongoMapper::Document has_many :comments end If I do: class
If you try this code.. you can see the problem I have.. class Embedded(EmbeddedDocument):
Currently I have an address column that is an embedded document in my users
I have embedded a Google Map in my website. I want to change its
I have embedded an IronPython engine in a C# application. I want to expose
I have a problem with relationships persisting in an embedded document. Here is the
How do I grab all articles with comments? I have: class Article include Mongoid::Document

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.