from sqlalchemy_utils import generic_relationship class Vote(db.Model): id = db.Column(db.Integer, primary_key=True) author_id = db.Column(db.Integer, db.ForeignKey("user.id")) vote = db.Column(db.Boolean) # This is used to discriminate between the linked tables. target_type = db.Column(db.Unicode(255)) # This is used to point to the primary key of the linked row. target_id = db.Column(db.Integer, nullable=False) target = generic_relationship(target_type, target_id) author = db.relationship("User") def __init__(self, author="", vote="", target=""): self.author = author self.vote = vote self.target = target