class Comments(db.Model): __tablename__ = 'comments' id = db.Column(db.Integer, primary_key=True, autoincrement=True) date = db.Column(db.Date) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) request_id = db.Column(db.Integer, db.ForeignKey('requests.id')) content = db.Column(db.Text) def __init__(self, date, user_id, request_id, content): self.date = date self.user_id = user_id self.request_id = request_id self.content = content
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) is_admin = db.Column(db.Boolean, default=False) active = db.Column(db.Boolean, default=True) def __init__(self, id=None, is_admin=None, active=None): self.id = id self.is_admin = is_admin self.active = active def get_id(self): try: return unicode(self.id) except AttributeError: raise NotImplementedError('No id attribute - override get_id') def get_by_id(self, id): try: dbUser = User.query.filter(User.id == id).first() return dbUser except Exception, e: print str(e)
class Updates(db.Model): __tablename__ = 'updates' id = db.Column(db.Integer, primary_key=True, autoincrement=True) request_id = db.Column(db.Integer, db.ForeignKey('requests.id')) date = db.Column(db.Date) content = db.Column(db.Text)
class Requests(db.Model): __tablename__ = 'requests' id = db.Column(db.Integer, primary_key=True, autoincrement=True) owner = db.Column(db.Integer, db.ForeignKey('users.id')) title = db.Column(db.String(511)) subtitle = db.Column(db.String(511)) content = db.Column(db.Text) supporters = db.Column(db.Text) status = db.Column(db.Text) approved = db.Column(db.Boolean, default=False) tags = db.Column(db.Text) priority = db.Column(db.Integer, default=3) # 3 = low comments_no = db.Column(db.Integer, default=0) date = db.Column(db.Date) def __init__(self, owner, title, subtitle, content, supporters, status, approved, tags, priority, date, comments_no): self.owner = owner self.title = title self.content = content self.supporters = supporters self.status = status self.approved = approved self.tags = tags self.priority = priority self.date = date self.comments_no = 0