class Report(db.Model): __tablename__ = 'report' id = db.Column(db.Integer,primary_key=True) user_id = db.Column(db.Integer,db.ForeignKey(User.id),index=True) post_id = db.Column(db.Integer,db.ForeignKey(Post.id),index=True) user = db.relation(User,innerjoin=True,lazy='joined') post = db.relation(Post,innerjoin=True,lazy='joined') date_create = db.Column(db.DateTime,default=datetime.now)
class UserLikeAsso(db.Model): __tablename__ = 'user_like_asso' id = db.Column(db.Integer,primary_key=True) user_id = db.Column(db.Integer,db.ForeignKey(User.id),index=True) post_id = db.Column(db.Integer,db.ForeignKey(Post.id),index=True) date_create = db.Column(db.DateTime,default=datetime.now) __table_args__ = ( db.UniqueConstraint('user_id','post_id'), )
class Post(db.Model): __tablename__ = 'post' id = db.Column(db.Integer,primary_key=True) title = db.Column(db.String(300)) pic_small = db.Column(db.String(255)) pic_big = db.Column(db.String(255)) video_url = db.Column(db.String(255)) author_id = db.Column(db.Integer,db.ForeignKey(User.id),index=True) show = db.Column(db.Boolean,default=True,index=True) recommended = db.Column(db.Boolean,default=False,index=True) play_count = db.Column(db.Integer,default=0) date_create = db.Column(db.DateTime,default=datetime.now) date_update = db.Column(db.DateTime,default=datetime.now) date_publish = db.Column(db.DateTime,default=datetime.now) user = db.relation(User, innerjoin=True, lazy="joined") @cached_property def json(self): video_prefix = current_app.config.get('VIDEO_URL_PREFIX') if current_app \ else DefaultConfig.VIDEO_URL_PREFIX return dict(id=self.id, title=self.title, pic_big=self.pic_big, pic_small=os.path.join(video_prefix,self.pic_small or ''), video_url=os.path.join(video_prefix,self.video_url or ''), author_id=self.author_id, show=self.show, recommended=self.recommended, play_count=self.play_count, date_create=format_date(self.date_create), date_update=format_date(self.date_update), date_publish=format_date(self.date_publish))
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer,primary_key=True) post_id = db.Column(db.Integer,index=True) author_id = db.Column(db.Integer,db.ForeignKey(User.id)) content = db.Column(db.String(1000)) show = db.Column(db.Boolean,default=True) date_create = db.Column(db.DateTime,default=datetime.now) @cached_property def json(self): return dict(id=self.id, post_id=self.post_id, author_id=self.author_id, content=self.content, show=self.show, date_create=format_date(self.date_create))
class Install(db.Model): __tablename__ = 'install' id = db.Column(db.Integer,primary_key=True) user_id = db.Column(db.Integer,db.ForeignKey(User.id),index=True,unique=True) version = db.Column(db.String(20)) badge = db.Column(db.Integer,default=0) device_token = db.Column(db.String(100),index=True) device_type = db.Column(db.String(20)) date_create = db.Column(db.DateTime,default=datetime.now) @property def json(self): return dict(id=self.id, user_id=self.user_id, version=self.version, badge=self.badge, device_token=self.device_token, device_type=self.device_type, date_create=format_date(self.date_create))