class Post(db.Model): __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.VARCHAR(50)) slug = db.Column(db.VARCHAR(50)) content = db.Column(db.VARCHAR(100)) id_user = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('Post', lazy='dynamic')) id_post_type = db.Column(db.Integer, db.ForeignKey('post_type.id')) post_type = db.relationship('Post_type', backref=db.backref('Post', lazy='dynamic')) createdtime = db.Column(db.DateTime) updatetime = db.Column(db.DateTime) deletedtime = db.Column(db.DateTime) deleted = db.Column(db.Boolean) def __init__(self, title, content, id_post_type, id_user): self.title = title self.content = content self.id_post_type = id_post_type self.id_user = id_user self.slug = slugify(unicode(self.title)) self.createdtime = datetime.datetime.now() self.updatetime = datetime.datetime.now() self.deleted = 0 def __repr__(self): return "<Post: %s>"%self.title
class Hotel(db.Model): #set table name __tablename__ = 'hotels' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) address = db.Column(db.String(50)) zipcode = db.Column(db.Integer()) city = db.relationship('City', backref='hotels', lazy='dynamic') province = db.relationship('Province', backref='hotels', lazy='dynamic') country = db.relationship('Country', backref='hotels', lazy='dynamic') hotelfacility_id = db.relationship('HotelFacility', backref='hotels', lazy='dynamic') price = db.Column(db.Float()) def __init__(self, name, address, zipcode, province, price): self.name = name self.address = address self.zipcode = zipcode self.city = city self.province = province self.country = country self.price = price def __repr__(self): return '<Hotel>{}'.format(self.name)
class Social_Media_User(db.Model): __tablename__ = 'social_media_user' id = db.Column(db.Integer, primary_key=True) id_socmed = db.Column(db.Integer, db.ForeignKey('social_media.id')) social_media = db.relationship('Social_Media', backref=db.backref('socmed_user', lazy='dynamic')) id_user = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('socmed_user', lazy='dynamic')) value = db.Column(db.VARCHAR(45)) createdtime = db.Column(db.DateTime) updatedtime = db.Column(db.DateTime) deletedtime = db.Column(db.DateTime) deleted = db.Column(db.Boolean)
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(50)) fullname = db.Column(db.String(50)) email = db.Column(db.String(20)) address = db.Column(db.String(50)) phone_number = db.Column(db.String(12)) password = db.Column(db.String(30)) profile = db.relationship('Profile', backref='user', lazy = 'dynamic') created_time = db.Column(db.DateTime, default = datetime.now) lastlogin_time = db.Column(db.DateTime) def __init__(self, username, fullname, email, address, phone_number, password): self.username = username self.fullname = fullname self.email = email self.address = address self.phone_number = phone_number self.password = password def __repr__(self): return '<User{}>'.format(self.username)
class Post_type(db.Model): __tablename__ = 'post_type' id = db.Column(db.Integer, primary_key=True) post_type = db.Column(db.VARCHAR(10)) created_by = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('Post_type', lazy='dynamic')) description = db.Column(db.VARCHAR(45))
class User_answer(db.Model): __tablename__ = 'user_answer' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('answers', lazy='dynamic')) question_id = db.Column(db.Integer, db.ForeignKey('question.id')) question = db.relationship('Question', backref=db.backref('answers', lazy='dynamic')) answer = db.Column(db.Boolean) def __init__(self, user_id, question_id, answer): self.user_id = user_id self.question_id = question_id self.answer = answer def __repr__(self): return '<UserAnswer %d>'%(self.answer)
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True) id_post = db.Column(db.Integer, db.ForeignKey('post.id')) post = db.relationship('Post', backref=db.backref('Comment', lazy='dynamic')) id_user = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('Comment', lazy='dynamic')) desc = db.Column(db.VARCHAR(50)) createdtime = db.Column(db.DateTime) updatetime = db.Column(db.DateTime) deletedtime = db.Column(db.DateTime) deleted = db.Column(db.Boolean) def __init__(self, id_post, id_user, desc): self.id_post = id_post self.id_user = id_user self.desc = desc self.createdtime = datetime.datetime.now() self.updatetime = datetime.datetime.now() self.deleted = 0
class Vote(db.Model): __tablename__ = 'vote' id = db.Column(db.Integer, primary_key=True) id_post = db.Column(db.Integer, db.ForeignKey('post.id')) post = db.relationship('Post', backref=db.backref('Vote', lazy='dynamic')) id_user = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('Vote', lazy='dynamic')) createdtime = db.Column(db.DateTime) updatetime = db.Column(db.DateTime) deletedtime = db.Column(db.DateTime) deleted = db.Column(db.Boolean) def __init__(self, id_post, id_user): self.id_post = id_post self.id_user = id_user self.createdtime = datetime.datetime.now() self.updatetime = datetime.datetime.now() self.deleted = 0 def __repr__(self): return "<Vote %s>"%self.post.title
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) full_name = db.Column(db.VARCHAR(45)) username = db.Column(db.VARCHAR(15), unique=True) password = db.Column(db.VARCHAR(128)) email = db.Column(db.VARCHAR(30), unique=True) bio = db.Column(db.VARCHAR(20)) picture = db.Column(db.VARCHAR(50)) updatedtime = db.Column(db.DateTime) createdtime = db.Column(db.DateTime) deletedtime = db.Column(db.DateTime) deleted = db.Column(db.Boolean) last_login = db.Column(db.DateTime) id_type_user = db.Column(db.Integer, db.ForeignKey('user_type.id')) type_user = db.relationship('User_Type', backref=db.backref('user', lazy='dynamic')) def __init__(self, full_name, username, email, password): self.full_name = full_name self.username = username self.email = email self.password = generate_password_hash(password) self.createdtime = datetime.datetime.now() self.updatedtime = datetime.datetime.now() self.deleted = 0 self.id_type_user = 5 def is_authenticated(self): return True def is_active(self): return True def get_id(self): return unicode(self.id) def is_anonymous(self): return False def __repr__(self): return "<Username: %s>"%self.username