users model
class User(db.Model):
__tablename__ = "users"
id = db.Column('user_id',db.Integer , primary_key=True)
username = db.Column('username', db.String(20), unique=True , index=True)
password = db.Column('password' , db.String(250))
posts = db.relationship('Post', backref = 'user', lazy = 'dynamic')
def __init__(self , username ,password ):
self.username = username
self.password = password
posts model
class Post(db.Model):
__tablename__ = 'posts'
id = db.Column(db.Integer, primary_key = True)
title = db.Column(db.String(140))
text = db.Column(db.String(2000))
user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'))
def __init__(self, title, text):
self.title = title
self.text = text
now I want to add comments model but dont know how to do it .please help me in comments view also . comments should be connected to user and post .
Thank You