class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True)
password = db.Column(db.String(30))
email = db.Column(db.String(45), unique=True)
friends = db.relationship('User', secondary=association_table, backref=
    'added_by', primaryjoin=id == association_table.c.user_id,
    secondaryjoin=id == association_table.c.friend_id)
Adding data to related table with SQLAlchemy