class FriendRequest(db.Model): """ Model for profile friend requests """ id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) friend_id = db.Column(db.Integer, db.ForeignKey('user.id')) user_accepted = db.Column(db.Boolean) friend_accepted = db.Column(db.Boolean) user_ignored = db.Column(db.Boolean) friend_ignored = db.Column(db.Boolean) created_on = db.Column(db.Date) accepted_on = db.Column(db.Date) def __init__(self, user_id, friend_id, user_accepted, friend_accepted, user_ignored, friend_ignored, created_on, accepted_on): self.user_id = user_id self.friend_id = friend_id self.user_accepted = user_accepted self.friend_accepted = friend_accepted self.user_ignored = user_ignored self.friend_ignored = friend_ignored self.created_on = created_on self.accepted_on = accepted_on def __repr__(self): return '<FriendRequest %r>' % self.user_id
class Bookmark(db.Model): """ Model for bookmark """ id = db.Column(db.Integer, primary_key=True) collection_id = db.Column(db.Integer, db.ForeignKey('collection.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) url = db.Column(db.String(256)) title = db.Column(db.String(256)) description = db.Column(db.Text(256)) text = db.Column(db.Text()) image = db.Column(db.Text(256)) tags = db.Column(db.String(256)) published_on = db.Column(db.String(256)) likes = db.Column(db.Integer) dislikes = db.Column(db.Integer) source = db.Column(db.String(256)) slug = db.Column(db.String(256), unique=True) # slug should be unique created_at = db.Column(db.Date) category_id = db.Column(db.Integer, db.ForeignKey('category.id')) # category relationship category = db.relationship('Category', backref=db.backref('bookmark', lazy='dynamic')) def __init__(self, collection, user, category, slug, url, title, source, published_on, description=None, image=None, text=None, tags=None): self.collection_id = collection.id self.user_id = user.id self.url = url self.title = title self.description = description self.image = image self.tags = tags self.published_on = published_on self.likes = 0 self.dislikes = 0 self.source = source self.slug = slug self.created_at = datetime.utcnow() self.category_id = category.id def __repr__(self): return '<Bookmark %r>' % self.title
class Comment(db.Model): """ Model for post comment """ id = db.Column(db.Integer, primary_key=True) post_id = db.Column(db.Integer, db.ForeignKey('post.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) posted_on = db.Column(db.Date) comment = db.Column(db.Text()) def __init__(self, post_id, user_id, posted_on, comment): self.post_id = post_id self.user_id = user_id self.posted_on = posted_on self.comment = comment def __repr__(self): return '<Comment %r>' % self.comment
class LiveComment(db.Model): """ Model for ArticlePool comments """ id = db.Column(db.Integer, primary_key=True) article_pool_id = db.Column(db.Integer, db.ForeignKey('article_pool.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) posted_on = db.Column(db.Date) comment = db.Column(db.Text()) def __init__(self, article_pool_id, user_id, posted_on, comment): self.article_pool_id = article_pool_id self.user_id = user_id self.posted_on = posted_on self.comment = comment def __repr__(self): return '<Comment %r>' % self.comment
class Collection(db.Model): """ Model for collection of bookmarks """ id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) name = db.Column(db.String(80)) image = db.Column(db.Text(256)) image_upload = db.Column(db.Text(256)) category = db.Column(db.String(80)) num_bookmarks = db.Column(db.Integer) # bookmark relationship bookmarks = db.relationship('Bookmark', backref='collection', lazy='dynamic') def __init__(self, name, user_id, num_bookmarks, image, image_upload, category): self.name = name self.user_id = user_id self.num_bookmarks = num_bookmarks self.image = image self.image_upload = image_upload self.category = category def __repr__(self): return '<Library %r>' % self.name
class Profile(db.Model): """ Model for profile """ id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) birthday = db.Column(db.Date) political_spectrum = db.Column(db.String(256)) political_party = db.Column(db.String(256)) # accepted as array -> convert in init favourite_news_websites = db.Column(db.Text()) allow_location_detection = db.Column(db.Boolean) location = db.Column(db.String(256)) lat = db.Column(db.Float) lon = db.Column(db.Float) def __init__(self, user_id, birthday, political_spectrum, political_party, favourite_news_websites, allow_location_detection, location, lat, lon): self.user_id = user_id self.birthday = birthday self.political_spectrum = political_spectrum self.political_party = political_party # convert list to comma-separated string self.favourite_news_websites = ",".join(favourite_news_websites) self.allow_location_detection = allow_location_detection self.location = location self.lat = lat self.lon = lon def __repr__(self): return '<Profile %r>' % self.user_id
class Friends(db.Model): """ Model for profile friends """ id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) friend_id = db.Column(db.Integer, db.ForeignKey('user.id')) created_on = db.Column(db.String(256)) accepted_on = db.Column(db.Date) def __init__(self, user_id, friend_id, created_on, accepted_on): self.user_id = user_id self.friend_id = friend_id self.created_on = created_on self.accepted_on = accepted_on def __repr__(self): return '<Friends %r>' % self.user_id
class Post(db.Model): """ Model for post """ id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) collection_id = db.Column(db.Integer, db.ForeignKey('collection.id')) bookmark_id = db.Column(db.Integer, db.ForeignKey('bookmark.id')) url = db.Column(db.String(256)) title = db.Column(db.String(256)) description = db.Column(db.Text(256)) text = db.Column(db.Text()) image = db.Column(db.Text(256)) tags = db.Column(db.String(256)) published_on = db.Column(db.String(256)) source = db.Column(db.String(256)) post = db.Column(db.Text()) posted_on = db.Column(db.Date) num_comments = db.Column(db.Integer) num_likes = db.Column(db.Integer) num_dislikes = db.Column(db.Integer) comments = db.relationship('Comment', backref='post', lazy='dynamic') def __init__(self, user_id, collection_id, bookmark_id, url, title, description, text, image, tags, published_on, source, post, posted_on, num_comments, num_likes, num_dislikes): self.user_id = user_id self.collection_id = collection_id self.bookmark_id = bookmark_id self.url = url self.title = title self.description = description self.text = text self.image = image self.tags = tags self.published_on = published_on self.source = source self.post = post self.posted_on = posted_on self.num_comments = num_comments self.num_likes = num_likes self.num_dislikes = num_dislikes def __repr__(self): return '<Post %r>' % self.post