class UserFollowersModel(db.Model): __tablename__ = 'user_followers' __table_args__ = {"schema": "mgn"} user_follower_id = db.Column(db.Integer, primary_key=True) follower = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) following = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) is_blocked = db.Column(db.SmallInteger, nullable=False) created = db.Column(db.DateTime, nullable=True) follower_user = db.relationship('MasterUserModel', foreign_keys=[follower], backref=db.backref('follower_user', lazy='dynamic')) following_user = db.relationship('MasterUserModel', foreign_keys=[following], backref=db.backref('following_user', lazy='dynamic')) @property def id(self): return self.user_follower_id def __init__(self, follower=None, following=None): self.follower = follower self.following = following self.is_blocked = FALSE self.created = datetime.datetime.utcnow() @property def serialize(self): return { 'id': self.user_follower_id, 'follower': self.follower_user.serialize, 'following': self.following_user.serialize, 'blocked': self.is_blocked, 'created': str(self.created) }
class UserMessageStatusModel(db.Model): __tablename__ = 'user_message_status' __table_args__ = {"schema": "mgn"} user_message_status_id = db.Column(db.Integer, primary_key=True) master_user_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) user_message_thread_id = db.Column( db.Integer, db.ForeignKey(UserMessageThreadsModel.user_message_thread_id), nullable=False) user_message_id = db.Column(db.Integer, db.ForeignKey( UserMessageModel.user_message_id), nullable=False) is_deleted = db.Column(db.SmallInteger, nullable=True) delete_timestamp = db.Column(db.DateTime, nullable=True) is_read = db.Column(db.SmallInteger, nullable=True) read_timestamp = db.Column(db.DateTime, nullable=True) created = db.Column(db.DateTime, nullable=False) archive = db.Column(db.SmallInteger, nullable=True) message_thread = db.relationship('UserMessageThreadsModel', backref=db.backref('message_thread', lazy='dynamic')) message_status_master_user = db.relationship( 'MasterUserModel', backref=db.backref('message_status_master_user', lazy='dynamic')) user_message = db.relationship('UserMessageModel', backref=db.backref('user_message', lazy='dynamic')) @property def id(self): return self.user_message_status_id def __init__(self, master_user_id=None, user_message_thread_id=None, user_message_id=None, last_message_timestamp=None): self.master_user_id = master_user_id self.user_message_thread_id = user_message_thread_id self.user_message_id = user_message_id self.is_read = FALSE self.is_deleted = FALSE self.archive = FALSE self.created = datetime.datetime.utcnow() @property def serialize(self): return { 'message': self.user_message.serialize, 'is_deleted': self.is_deleted, 'delete_timestamp': str(self.delete_timestamp), 'is_read': self.is_read, 'read_timestamp': str(self.read_timestamp), 'created': self.created }
class MasterUserSettingModel(db.Model): __tablename__ = 'master_user_setting' __table_args__ = {"schema": "mgn"} master_user_setting_id = db.Column(db.BigInteger, primary_key=True) master_user_id = db.Column(db.BigInteger, db.ForeignKey(MasterUserModel.master_user_id)) master_language_id = db.Column( db.Integer, db.ForeignKey(MasterLanguageModel.master_language_id)) timezone_id = db.Column(db.Integer, db.ForeignKey(MasterTimezoneModel.timezone_id)) master_currency_id = db.Column( db.Integer, db.ForeignKey(MasterCurrencyModel.master_currency_id)) master_user = db.relationship('MasterUserModel', backref=db.backref('user', lazy='dynamic')) master_timezone = db.relationship('MasterTimezoneModel', backref=db.backref('timezone', lazy='dynamic')) master_language = db.relationship('MasterLanguageModel', backref=db.backref('language', lazy='dynamic')) master_currency = db.relationship('MasterCurrencyModel', backref=db.backref('currency', lazy='dynamic')) @property def id(self): return self.master_user_setting_id def __init__(self, master_user_id=None, master_language_id=None, timezone_id=None, master_currency_id=None): self.master_user_id = master_user_id self.master_language_id = master_language_id self.timezone_id = timezone_id self.master_currency_id = master_currency_id @property def serialize(self): return { 'id': self.master_user_setting_id, 'user': self.master_user.serialize, 'language': self.master_language.serialize, 'timezone': self.master_timezone.serialize, 'currency': self.master_currency.serialize }
class UserMessageThreadsModel(db.Model): __tablename__ = 'user_message_threads' __table_args__ = {"schema": "mgn"} user_message_thread_id = db.Column(db.Integer, primary_key=True) thread_creator_master_user_id = db.Column( db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) last_user_message_id = db.Column(db.Integer, db.ForeignKey( UserMessageModel.user_message_id), nullable=True) created = db.Column(db.DateTime, nullable=False) last_user_message = db.relationship('UserMessageModel', backref=db.backref('last_user_message', lazy='dynamic')) message_thread_creator = db.relationship('MasterUserModel', backref=db.backref( 'message_thread_creator', lazy='dynamic')) @property def id(self): return self.user_message_thread_id def __init__(self, thread_creator_master_user_id=None): self.thread_creator_master_user_id = thread_creator_master_user_id self.created = datetime.datetime.utcnow() @property def serialize(self): if self.last_user_message is not None: return { 'message_thread_creator': self.message_thread_creator.serialize, 'last_user_message': self.last_user_message.serialize, 'created': str(self.created), 'id': self.user_message_thread_id } else: return { 'message_thread_creator': self.message_thread_creator.serialize, 'last_user_message': self.last_user_message, 'created': str(self.created), 'id': self.user_message_thread_id }
class CommentsModel(db.Model): __tablename__ = 'comments' __table_args__ = {"schema": "mgn"} comment_id = db.Column(db.Integer, primary_key=True, nullable=False) comment_thread_id = db.Column(db.Integer, db.ForeignKey(CommentThreadsModel.comment_thread_id), nullable=False) comment_reply_thread_id = db.Column(db.Integer, db.ForeignKey(CommentThreadsModel.comment_thread_id), nullable=True) master_user_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) comment = db.Column(db.String(200), nullable=False) created = db.Column(db.DateTime, nullable=False) comment_master_user = db.relationship('MasterUserModel', backref=db.backref('comment_master_user', lazy='dynamic')) @property def id(self): return self.comment_id def __init__(self, master_user_id=None, comment_thread_id=None, comment_reply_thread_id=None, comment=None): self.master_user_id = master_user_id self.comment_thread_id = comment_thread_id self.comment_reply_thread_id = comment_reply_thread_id self.comment = comment self.created = datetime.datetime.utcnow() @property def serialize(self): return { 'user': self.comment_master_user.serialize, 'comment': self.comment, 'reply_thread': self.comment_reply_thread_id, 'created': str(self.created) }
class UserNotificationsModel(db.Model): __tablename__ = 'user_notifications' __table_args__ = {"schema": "mgn"} user_notification_id = db.Column(db.Integer, primary_key=True) master_user_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) notifications = db.Column(JSONB, nullable=False) notification_user = db.relationship('MasterUserModel', backref=db.backref('notification_user', lazy='dynamic')) @property def id(self): return self.user_notification_id def __init__(self, master_user_id=None, notifications=None): self.master_user_id = master_user_id self.notifications = notifications @property def serialize(self): return { 'id': self.user_notification_id, 'user': self.notification_user.serialize, 'notifications': self.notifications }
class UserAccessDetailsModel(db.Model): __tablename__ = 'user_access_details' __table_args__ = {"schema": "mgn"} user_access_details_id = db.Column(db.Integer, primary_key=True) master_user_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) access_history = db.Column(JSONB, nullable=True) latitude = db.Column(db.Float, nullable=True) longitude = db.Column(db.Float, nullable=True) city = db.Column(db.String(50), nullable=True) state = db.Column(db.String(50), nullable=True) zipcode = db.Column(db.String(15), nullable=True) country_code = db.Column(db.String(5), nullable=True) browser = db.Column(db.String(100), nullable=True) device = db.Column(db.String(100), nullable=True) request_string = db.Column(db.String(150), nullable=True) platform = db.Column(db.String(50), nullable=True) updated = db.Column(db.DateTime, nullable=False) master_user = db.relationship('MasterUserModel', backref=db.backref('access_user', lazy='dynamic')) @property def id(self): return self.user_profile_id def __init__(self, master_user_id=None, access_history=None, latitude=None, longitude=None, city=None, state=None, zipcode=None, country_code=None, browser=None, device=None,request_string=None, platform=None): self.master_user_id = master_user_id self.access_history = access_history self.latitude = latitude self.longitude = longitude self.city = city self.state = state self.zipcode = zipcode self.country_code = country_code self.browser = browser self.device = device self.request_string = request_string self.platform = platform self.updated = datetime.datetime.now() @property def serialize(self): return { 'user': self.master_user.serialize, 'access_history': self.access_history, 'latitude': self.latitude, 'longitude': self.longitude, 'city': self.city, 'state': self.state, 'zipcode': self.zipcode, 'country_code': self.country_code, 'browser': self.browser, 'device': self.device, 'request_string': self.request_string, 'platform': self.platform, 'updated': str(self.updated) }
class UserProfileModel(db.Model): __tablename__ = 'user_profile' __table_args__ = {"schema": "mgn"} user_profile_id = db.Column(db.Integer, primary_key=True) profile_banner_image = db.Column(db.String(200), nullable=True) dob = db.Column(db.Date, nullable=True) master_gender_id = db.Column(db.SmallInteger, db.ForeignKey( MasterGenderModel.master_gender_id), nullable=False) master_user_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) master_gender = db.relationship('MasterGenderModel', backref=db.backref('master_gender', lazy='dynamic')) master_user = db.relationship('MasterUserModel', backref=db.backref('master_user', lazy='dynamic')) @property def id(self): return self.user_profile_id def __init__(self, profile_pic=None, profile_banner_image=None, dob=None, master_gender_id=None, master_user_id=None): self.profile_banner_image = profile_banner_image self.dob = dob self.master_gender_id = master_gender_id self.master_user_id = master_user_id @property def serialize(self): return { 'profile_banner_image': self.profile_banner_image, 'dob': str(self.dob), 'gender': self.master_gender.serialize, 'user': self.master_user.serialize }
class UserConnectionsModel(db.Model): __tablename__ = 'user_connections' __table_args__ = {"schema": "mgn"} user_connection_id = db.Column(db.Integer, primary_key=True) connected_from_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) connected_to_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) user_message_thread_id = db.Column(db.Integer, db.ForeignKey( UserMessageThreadParticipantsModel.user_message_thread_id), nullable=True) is_accepted = db.Column(db.SmallInteger, nullable=False) is_blocked = db.Column(db.SmallInteger, nullable=False) is_ignored = db.Column(db.SmallInteger, nullable=False) created = db.Column(db.DateTime, nullable=False) master_user_from = db.relationship('MasterUserModel', foreign_keys=[connected_from_id], backref=db.backref('master_user_from', lazy='dynamic')) master_user_to = db.relationship('MasterUserModel', foreign_keys=[connected_to_id], backref=db.backref('master_user_to', lazy='dynamic')) connection_message_thread = db.relationship('UserMessageThreadParticipantsModel', backref=db.backref('connection_message_thread', lazy='dynamic')) @property def id(self): return self.user_connection_id def __init__(self, connected_from_id=None, connected_to_id=None): self.connected_from_id = connected_from_id self.connected_to_id = connected_to_id self.is_accepted = FALSE self.is_blocked = FALSE self.is_ignored = FALSE self.created = datetime.datetime.utcnow() @property def serialize(self): return { 'connection': self.master_user_to.serialize, 'message_thread': self.user_message_thread_id, 'accepted': self.is_accepted, 'blocked': self.is_blocked, 'ignored': self.is_ignored, 'created': str(self.created) }
class UserMessageModel(db.Model): __tablename__ = 'user_messages' __table_args__ = {"schema": "mgn"} user_message_id = db.Column(db.Integer, primary_key=True) sent_from_master_user_id = db.Column(db.Integer, db.ForeignKey( MasterUserModel.master_user_id), nullable=False) """Thread foreign key removed because of compile exception""" user_message_thread_id = db.Column(db.Integer, nullable=False) message_text = db.Column(db.String(400), nullable=False) has_attachment = db.Column(db.SmallInteger, nullable=False) attachment_url = db.Column(db.String(200), nullable=False) created = db.Column(db.DateTime, nullable=False) sent_from_master_user = db.relationship('MasterUserModel', backref=db.backref( 'sent_from_master_user', lazy='dynamic')) @property def id(self): return self.user_message_id def __init__(self, sent_from_master_user_id=None, user_message_thread_id=None, message_text=None, has_attachment=FALSE, attachment_url=None): self.sent_from_master_user_id = sent_from_master_user_id self.user_message_thread_id = user_message_thread_id self.message_text = message_text self.has_attachment = has_attachment self.attachment_url = attachment_url self.created = datetime.datetime.utcnow() @property def serialize(self): return { 'id': self.user_message_id, 'sent_from_master_user': self.sent_from_master_user.serialize, 'message_text': self.message_text, 'has_attachment': self.has_attachment, 'attachment_url': self.attachment_url, 'created': str(self.created) }
class BlogsModel(db.Model): __tablename__ = 'user_blogs' __table_args__ = {"schema": "mgn"} user_blog_id = db.Column(db.Integer, primary_key=True, nullable=False) blogger_master_user_id = db.Column(db.Integer, db.ForeignKey( MasterUserModel.master_user_id), nullable=False) blog_name = db.Column(db.String(200), nullable=False) blog_subject = db.Column(db.String(100), nullable=False) blog_body = db.Column(db.String, nullable=False) comment_thread_id = db.Column(db.Integer, db.ForeignKey( CommentThreadsModel.comment_thread_id), nullable=False) like_thread_id = db.Column(db.Integer, db.ForeignKey(LikeThreadsModel.like_thread_id), nullable=False) visit_count = db.Column(db.SmallInteger, nullable=False) like_count = db.Column(db.SmallInteger, nullable=False) comment_count = db.Column(db.SmallInteger, nullable=False) share_count = db.Column(db.SmallInteger, nullable=False) tags = db.Column(JSONB, nullable=False) updated = db.Column(db.DateTime, nullable=False) created = db.Column(db.DateTime, nullable=False) blog_master_user = db.relationship('MasterUserModel', backref=db.backref('blog_master_user', lazy='dynamic')) @property def id(self): return self.blog_id def __init__(self, master_user_id=None, blog_name=None, blog_subject=None, blog_body=None, comment_thread_id=None, like_thread_id=None, tags=None): self.blogger_master_user_id = master_user_id self.blog_name = blog_name self.blog_subject = blog_subject self.blog_body = blog_body self.comment_thread_id = comment_thread_id self.like_thread_id = like_thread_id self.tags = tags self.visit_count = 0 self.like_count = 0 self.comment_count = 0 self.share_count = 0 self.updated = datetime.datetime.utcnow() self.created = datetime.datetime.utcnow() @property def serialize(self): return { 'user': self.blog_master_user.serialize, 'url': url_for("blogs_services.get", blog_name=self.blog_name), 'blog_id': self.user_blog_id, 'blog_subject': self.blog_subject, 'blog_body': self.blog_body, 'comment_thread_id': self.comment_thread_id, 'like_thread_id': self.like_thread_id, 'tags': self.tags, 'visit_count': self.visit_count, 'like_count': self.like_count, 'comment_count': self.comment_count, 'share_count': self.share_count, 'updated': str(self.updated), 'created': str(self.created) }
class UserMessageThreadParticipantsModel(db.Model): __tablename__ = 'user_message_thread_participants' __table_args__ = {"schema": "mgn"} user_message_thread_participants_id = db.Column(db.Integer, primary_key=True) master_user_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) user_message_thread_id = db.Column(db.Integer, db.ForeignKey(UserMessageThreadsModel.user_message_thread_id), nullable=False) is_deleted = db.Column(db.SmallInteger, nullable=True) delete_timestamp = db.Column(db.DateTime, nullable=True) is_spam = db.Column(db.SmallInteger, nullable=True) spam_timestamp = db.Column(db.DateTime, nullable=True) has_left_group = db.Column(db.SmallInteger, nullable=True) has_left_group_timestamp = db.Column(db.DateTime, nullable=True) is_muted = db.Column(db.SmallInteger, nullable=True) is_muted_timestamp = db.Column(db.DateTime, nullable=True) is_read = db.Column(db.SmallInteger, nullable=True) last_read_timestamp = db.Column(db.DateTime, nullable=True) unread_message_count = db.Column(db.SmallInteger, nullable=True) last_message_timestamp = db.Column(db.DateTime, nullable=True) archive = db.Column(db.SmallInteger, nullable=True) participants_message_thread = db.relationship('UserMessageThreadsModel', backref=db.backref('participants_message_thread', lazy='dynamic')) message_thread_master_user = db.relationship('MasterUserModel', backref=db.backref('message_thread_master_user', lazy='dynamic')) @property def id(self): return self.user_message_thread_participants_id def __init__(self, master_user_id=None, user_message_thread_id=None): self.master_user_id = master_user_id self.user_message_thread_id = user_message_thread_id self.is_deleted = FALSE self.is_spam = FALSE self.is_muted = FALSE self.is_read = FALSE self.has_left_group = FALSE self.archive = FALSE self.unread_message_count = 0 @staticmethod def get_participants(thread_id=None, master_user_id=None): data = UserMessageThreadParticipantsModel.query.filter( and_( UserMessageThreadParticipantsModel.user_message_thread_id == thread_id, UserMessageThreadParticipantsModel.master_user_id != master_user_id ) ) result = [i.serialize_participants for i in data.all()] return json.dumps(result) @property def serialize(self): return { 'message_thread_master_user': self.message_thread_master_user.serialize, 'message_thread': self.participants_message_thread.serialize, 'is_deleted': self.is_deleted, 'delete_timestamp': str(self.delete_timestamp), 'is_spam': self.is_spam, 'spam_timestamp': str(self.spam_timestamp), 'has_left_group': self.has_left_group, 'has_left_group_timestamp': str(self.has_left_group_timestamp), 'is_muted': self.is_muted, 'is_muted_timestamp': str(self.is_muted_timestamp), 'is_read': self.is_read, 'last_read_timestamp': str(self.last_read_timestamp), 'unread_message_count': self.unread_message_count, 'last_message_timestamp': self.last_message_timestamp, 'participants': str(self.get_participants(self.user_message_thread_id, self.master_user_id)) } @property def serialize_participants(self): return self.message_thread_master_user.serialize
class PostsModel(db.Model): __tablename__ = 'user_posts' __table_args__ = {"schema": "mgn"} user_post_id = db.Column(db.Integer, primary_key=True, nullable=False) post_text = db.Column(db.String(200), nullable=False) has_attachment = db.Column(db.SmallInteger, nullable=False) attachment_url = db.Column(db.String(200), nullable=False) comment_thread_id = db.Column(db.Integer, db.ForeignKey( CommentThreadsModel.comment_thread_id), nullable=False) like_thread_id = db.Column(db.Integer, db.ForeignKey(LikeThreadsModel.like_thread_id), nullable=False) created_by_master_user_id = db.Column(db.Integer, db.ForeignKey( MasterUserModel.master_user_id), nullable=False) like_count = db.Column(db.SmallInteger, nullable=True) comment_count = db.Column(db.SmallInteger, nullable=True) share_count = db.Column(db.SmallInteger, nullable=True) created = db.Column(db.DateTime, nullable=False) post_master_user = db.relationship('MasterUserModel', backref=db.backref('post_master_user', lazy='dynamic')) @property def id(self): return self.post_id def __init__(self, created_by_master_user_id=None, post_text=None, has_attachment=None, attachment_url=None, comment_thread_id=None, like_thread_id=None): self.created_by_master_user_id = created_by_master_user_id self.post_text = post_text self.has_attachment = has_attachment self.attachment_url = attachment_url self.comment_thread_id = comment_thread_id self.like_thread_id = like_thread_id self.like_count = 0 self.comment_count = 0 self.share_count = 0 self.created = datetime.datetime.utcnow() @property def serialize(self): return { 'post_id': self.user_post_id, 'user': self.post_master_user.serialize, 'post': self.post_text, 'attachment_url': self.attachment_url, 'comment_thread_id': self.comment_thread_id, 'like_thread_id': self.like_thread_id, 'like_count': self.like_count, 'comment_count': self.comment_count, 'share_count': self.share_count, 'created': str(self.created) }
class SharesModel(db.Model): __tablename__ = 'shares' __table_args__ = {"schema": "mgn"} share_id = db.Column(db.Integer, primary_key=True, nullable=False) master_user_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey(PostsModel.user_post_id), nullable=True) blog_id = db.Column(db.Integer, db.ForeignKey(BlogsModel.user_blog_id), nullable=True) url = db.Column(db.String(200), nullable=True) comment_thread_id = db.Column(db.Integer, db.ForeignKey(CommentThreadsModel.comment_thread_id), nullable=False) like_thread_id = db.Column(db.Integer, db.ForeignKey(LikeThreadsModel.like_thread_id), nullable=False) like_count = db.Column(db.SmallInteger, nullable=True) comment_count = db.Column(db.SmallInteger, nullable=True) share_count = db.Column(db.SmallInteger, nullable=True) created = db.Column(db.DateTime, nullable=False) shared_master_user = db.relationship('MasterUserModel', backref=db.backref('share_master_user', lazy='dynamic')) shared_post = db.relationship('PostsModel', backref=db.backref('shared_post', lazy='dynamic')) shared_blog = db.relationship('BlogsModel', backref=db.backref('shared_blog', lazy='dynamic')) @property def id(self): return self.share_id def __init__(self, master_user_id=None, post_id=None, blog_id=None, url=None, comment_thread_id=None, like_thread_id=None): self.master_user_id = master_user_id self.post_id = post_id self.blog_id = blog_id self.url = url self.comment_thread_id = comment_thread_id self.like_thread_id = like_thread_id self.like_count = 0 self.comment_count = 0 self.share_count = 0 self.created = datetime.datetime.utcnow() @property def serialize(self): if self.shared_post is not None: return { 'share_id': self.share_id, 'share_type': 'post', 'user': self.shared_master_user.serialize, 'shared_post': self.shared_post.serialize, 'comment_thread_id': self.comment_thread_id, 'like_thread_id': self.like_thread_id, 'like_count': self.like_count, 'comment_count': self.comment_count, 'share_count': self.share_count, 'created': str(self.created) } elif self.shared_blog is not None: return { 'share_id': self.share_id, 'share_type': 'blog', 'user': self.shared_master_user.serialize, 'shared_blog': self.shared_blog.serialize, 'comment_thread_id': self.comment_thread_id, 'like_thread_id': self.like_thread_id, 'like_count': self.like_count, 'comment_count': self.comment_count, 'share_count': self.share_count, 'created': str(self.created) } elif self.url is not None: return { 'share_id': self.share_id, 'share_type': 'url', 'user': self.shared_master_user.serialize, 'shared_url': self.url, 'comment_thread_id': self.comment_thread_id, 'like_thread_id': self.like_thread_id, 'like_count': self.like_count, 'comment_count': self.comment_count, 'share_count': self.share_count, 'created': str(self.created) }
class LikesModel(db.Model): __tablename__ = 'likes' __table_args__ = {"schema": "mgn"} like_id = db.Column(db.Integer, primary_key=True, nullable=False) master_user_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) like_thread_id = db.Column(db.Integer, db.ForeignKey(LikeThreadsModel.like_thread_id), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey(PostsModel.user_post_id), nullable=True) blog_id = db.Column(db.Integer, db.ForeignKey(BlogsModel.user_blog_id), nullable=True) share_id = db.Column(db.Integer, db.ForeignKey(SharesModel.share_id), nullable=True) created = db.Column(db.DateTime, nullable=False) liked_master_user = db.relationship('MasterUserModel', backref=db.backref('liked_master_user', lazy='dynamic')) liked_thread = db.relationship('LikeThreadsModel', backref=db.backref('liked_thread', lazy='dynamic')) liked_post = db.relationship('PostsModel', backref=db.backref('liked_post', lazy='dynamic')) liked_blog = db.relationship('BlogsModel', backref=db.backref('liked_blog', lazy='dynamic')) liked_share = db.relationship('SharesModel', backref=db.backref('liked_share', lazy='dynamic')) @property def id(self): return self.like_id def __init__(self, master_user_id=None, like_thread_id=None, post_id=None, blog_id=None, share_id=None): self.master_user_id = master_user_id self.like_thread_id = like_thread_id self.post_id = post_id self.blog_id = blog_id self.share_id = share_id self.created = datetime.datetime.utcnow() @property def serialize(self): return { 'like_id': self.like_id, 'liked_master_user': self.liked_master_user.serialize, 'liked_thread': self.liked_thread.serialize, 'liked_post': self.liked_post.serialize, 'liked_blog': self.liked_blog.serialize, 'liked_share': self.liked_share.serialize, 'created': str(self.created) }
class TimelineModel(db.Model): __tablename__ = 'timeline' __table_args__ = {"schema": "mgn"} timeline_id = db.Column(db.Integer, primary_key=True, nullable=False) master_user_id = db.Column(db.Integer, db.ForeignKey(MasterUserModel.master_user_id), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey(PostsModel.user_post_id), nullable=True) blog_id = db.Column(db.Integer, db.ForeignKey(BlogsModel.user_blog_id), nullable=True) share_id = db.Column(db.Integer, db.ForeignKey(SharesModel.share_id), nullable=True) comment_id = db.Column(db.Integer, db.ForeignKey(CommentsModel.comment_id), nullable=False) like_id = db.Column(db.Integer, db.ForeignKey(LikesModel.like_id), nullable=False) timeline_activity_type_id = db.Column(db.Integer, db.ForeignKey(TimelineActivityTypeModel.timeline_activity_type_id), nullable=False) created = db.Column(db.DateTime, nullable=False) timeline_user = db.relationship('MasterUserModel', backref=db.backref('timeline_user', lazy='dynamic')) timeline_post = db.relationship('PostsModel', backref=db.backref('timeline_post', lazy='dynamic')) timeline_blog = db.relationship('BlogsModel', backref=db.backref('timeline_blog', lazy='dynamic')) timeline_comment = db.relationship('CommentsModel', backref=db.backref('timeline_comment', lazy='dynamic')) timeline_like = db.relationship('LikesModel', backref=db.backref('timeline_like', lazy='dynamic')) timeline_share = db.relationship('SharesModel', backref=db.backref('timeline_share', lazy='dynamic')) timeline_activity = db.relationship('TimelineActivityTypeModel', backref=db.backref('timeline_activity', lazy='dynamic')) @property def id(self): return self.timeline_id def __init__(self, master_user_id=None, post_id=None, blog_id=None, share_id=None, comment_id=None, like_id=None, timeline_activity_type_id=None): self.master_user_id = master_user_id self.post_id = post_id self.blog_id = blog_id self.share_id = share_id self.comment_id = comment_id self.timeline_activity_type_id = timeline_activity_type_id self.like_id = like_id self.created = datetime.datetime.utcnow() @property def serialize(self): if self.timelined_post is not None: return { 'timeline_id': self.timeline_id, 'timelinetimeline_activity_type_id': self.timeline_activity_type_id, 'user': self.timelined_master_user.serialize, 'timelined_post': self.timelined_post.serialize, 'created': str(self.created) } elif self.timelined_blog is not None: return { 'timeline_id': self.timeline_id, 'timelinetimeline_activity_type_id': self.timeline_activity_type_id, 'user': self.timelined_master_user.serialize, 'timelined_blog': self.timelined_blog.serialize, 'created': str(self.created) } elif self.timeline_share is not None: return { 'timeline_id': self.timeline_id, 'timelinetimeline_activity_type_id': self.timeline_activity_type_id, 'user': self.timelined_master_user.serialize, 'timeline_share': self.timeline_share.serialize, 'created': str(self.created) } elif self.timeline_comment is not None: return { 'timeline_id': self.timeline_id, 'timelinetimeline_activity_type_id': self.timeline_activity_type_id, 'user': self.timelined_master_user.serialize, 'timeline_comment': self.timeline_comment.serialize, 'created': str(self.created) } elif self.timeline_like is not None: return { 'timeline_id': self.timeline_id, 'timelinetimeline_activity_type_id': self.timeline_activity_type_id, 'user': self.timelined_master_user.serialize, 'timeline_like': self.timeline_like.serialize, 'created': str(self.created) }