I have models:

{
class Post(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    body = db.Column(db.String(2000))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    comments = db.relationship('Comment', backref='parent_post', lazy='dynamic')

    class Comment(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    body = db.Column(db.String(140))
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
}

When entering a post to database I do this:

{
if form.validate_on_submit():
      post = Post(body=form.post.data, author=g.user)
      db.session.add(post)
      db.session.commit()
} This is working right.

But how can I enter a comment to database if I want to pass the 'post.id' value 
directly 
instead of object 'post'. (Not able to 'pass' object via form in html)

{
if form.validate_on_submit():
      comment = Comment(body=form.post.data, parent_post=form.p_id.data)
      db.session.add(post)
      db.session.commit()
}

currenntly p_id holds value post.id and it gives me error:
AttributeError: 'int' object has no attribute '_sa_instance_state'
Please help

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to