Пример #1
0
class FriendRequest(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    sender_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    receiver_id = db.Column(db.Integer,
                            db.ForeignKey('user.id'),
                            nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
Пример #2
0
class BookInShelf(db.Model):  #link between Book and Shelf
    id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('book.id'), nullable=False)
    shelf_id = db.Column(db.Integer, db.ForeignKey('shelf.id'), nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
    book = db.relationship('Book', back_populates='shelves')
    shelf = db.relationship('Shelf', back_populates='books')
Пример #3
0
class Message(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text, nullable=False)
    sender_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    receiver_id = db.Column(db.Integer,
                            db.ForeignKey('user.id'),
                            nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
Пример #4
0
class UserLikedUpdate(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    update_id = db.Column(db.Integer,
                          db.ForeignKey('update.id'),
                          nullable=False)
    user = db.relationship('User', back_populates='liked_updates')
    update = db.relationship('Update', back_populates='likes')
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
Пример #5
0
class UserLikedReview(db.Model, SerializerMixin):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    review_id = db.Column(db.Integer,
                          db.ForeignKey('review.id'),
                          nullable=False)
    user = db.relationship('User', back_populates='liked_reviews')
    review = db.relationship('Review', back_populates='likes')
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
Пример #6
0
class SimilarBooks(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('book.id'), nullable=False)
    similar_book_id = db.Column(db.Integer,
                                db.ForeignKey('book.id'),
                                nullable=False)

    def get_similar_book(self):
        return Book.query.get(self.similar_book_id)
Пример #7
0
class AuthorBookLink(db.Model):  #link between Author and Book
    __tablename__ = 'author_book_link'
    author_id = db.Column(db.Integer,
                          db.ForeignKey('author.id'),
                          primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('book.id'), primary_key=True)
    author_role = db.Column(db.String(50))
    author = db.relationship('Author', back_populates='books')
    book = db.relationship('Book', back_populates='authors')
Пример #8
0
class UserCommentedReview(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    review_id = db.Column(db.Integer,
                          db.ForeignKey('review.id'),
                          nullable=False)
    user = db.relationship('User', back_populates='review_comments')
    review = db.relationship('Review', back_populates='comments')
    comment = db.Column(db.Text, nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
Пример #9
0
class Review(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    book_id = db.Column(db.Integer, db.ForeignKey('book.id'), nullable=False)
    rating = db.Column(db.Integer, nullable=False)
    review = db.Column(db.Text, nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
    likes = db.relationship('UserLikedReview',
                            back_populates='review',
                            cascade="all, delete-orphan")
    comments = db.relationship('UserCommentedReview',
                               back_populates='review',
                               cascade="all, delete-orphan")
Пример #10
0
class Shelf(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    name = db.Column(db.String(100), nullable=False)
    books = db.relationship('BookInShelf',
                            back_populates='shelf',
                            cascade="all, delete-orphan")
Пример #11
0
class Notification(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    is_read = db.Column(db.Boolean, nullable=False, default=False)
    timestamp = db.Column(db.DateTime, nullable=False, default=datetime.now)
    event_type = db.Column(db.String(30), nullable=False)
    event_id = db.Column(db.Integer)

    def get_event(self):
        if self.event_type == 'review_like':
            event = UserLikedReview.query.get(self.event_id)
            return event, event.review
        elif self.event_type == 'update_like':
            event = UserLikedUpdate.query.get(self.event_id)
            return event, event.update
        elif self.event_type == 'review_comment':
            event = UserCommentedReview.query.get(self.event_id)
            return event, event.review
        event = UserCommentedUpdate.query.get(self.event_id)
        return event, event.update

    def get_notification_message(self):
        if self.event_type == 'review_like':
            target = UserLikedReview.query.get(self.event_id).review
            message = ' liked your review: ' + '"' + target.review[:50] + '..."'
        elif self.event_type == 'update_like':
            message = ' liked your update'
        elif self.event_type == 'review_comment':
            target = UserCommentedReview.query.get(self.event_id).review
            message = ' commented on your review: ' + target.review
        else:
            message = ' commented on your update'
        return message
Пример #12
0
class Update(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    timestamp = db.Column(db.DateTime, nullable=False, default=datetime.now)
    event_type = db.Column(db.String(30), nullable=False)
    event_id = db.Column(db.Integer)
    likes = db.relationship('UserLikedUpdate',
                            back_populates='update',
                            cascade="all, delete-orphan")
    comments = db.relationship('UserCommentedUpdate',
                               back_populates='update',
                               cascade="all, delete-orphan")

    def get_event(self):
        if self.event_type == 'review':
            return Review.query.get(self.event_id)
        return BookInShelf.query.get(self.event_id)
Пример #13
0
class BookInGenre(db.Model):  #link between Book and Genre
    id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('book.id'), nullable=False)
    genre_id = db.Column(db.Integer, db.ForeignKey('genre.id'), nullable=False)
    book = db.relationship('Book', back_populates='genres')
    genre = db.relationship('Genre', back_populates='books')
Пример #14
0
class Friendship(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    friend_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
Пример #15
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    text = db.Column(db.Text)