from sqlalchemy_utils import generic_relationship class Vote db Model

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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