Exemple #1
0
class User(UserMixin, db.Model):
    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(40), unique=True)
    name = db.Column(db.String(64))
    email = db.Column(db.String(64), unique=True)
    password = db.Column(db.String(64))
Exemple #2
0
class User(db.Model, UserMixin):

    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(40),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)

    def get_reset_token(self, expires_sec=1800):

        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):

        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']

        except:
            return None

        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}','{self.email}','{self.image_file}'')"
class BookRating(db.Model):
    id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
    book_id = db.Column(db.Integer, db.ForeignKey('book.id'),
        nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'),
        nullable=False)
    rating = db.Column(db.Integer, default=0)
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
    password = db.Column(db.String(100))
    username = db.Column(db.String(1000), unique=True)
    ratings = db.relationship('BookRating', backref='user', lazy=True)

    def __repr__(self):
        return("User: {}".format(self.username))
class Book(db.Model):
    id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
    title = db.Column(db.String(100))
    author = db.Column(db.String(1000))
    ratings = db.relationship('BookRating', backref='book', lazy=True)

    def __repr__(self):
        return("Book: {}".format(self.title))
Exemple #6
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(25), nullable=False)
    password = db.Column(db.String(60), nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')

    reviews = db.relationship("Review", back_populates="users")
Exemple #7
0
class User(db.Model, UserMixin):
    email = db.Column(db.String(50), nullable=False, primary_key=True)
    first_name = db.Column(db.String(20), nullable=False)
    last_name = db.Column(db.String(20), nullable=False)
    passwrd = db.Column(db.String(60), nullable=False)
    uploads = db.relationship('File', backref='owner', lazy=True)

    def __repr__(self):
        return f"User('{self.first_name}', '{self.last_name}', '{self.email}')"

    def get_id(self):
        return (self.email)
Exemple #8
0
class Post(db.Model):

    __tablename__ = "post"
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(60), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.now())
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):

        return f"Post('{self.title}','{self.date_posted}')"
Exemple #9
0
class Answers(db.Model, UserMixin):
    
    id = db.Column(db.Integer, primary_key = True)
    Answers1 = db.Column(db.String(10),   nullable = False)
    Answers2 = db.Column(db.String(10),   nullable = False)
    Answer3 = db.Column(db.String(10),   nullable = False)
    Answers4 = db.Column(db.String(10),   nullable = False)
    Answers5 = db.Column(db.String(10),   nullable = False)
    Submitted_by = db.Column(db.Integer, nullable = False)
Exemple #10
0
class Book(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    isbn = db.Column(db.String(25), nullable=False)
    title = db.Column(db.String(50), nullable=False)
    author = db.Column(db.String(25), nullable=False)
    year = db.Column(db.Integer, nullable=False)
    count_ratings = db.Column(db.Integer)
    overall_rating = db.Column(db.Float)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')

    reviews = db.relationship("Review", back_populates="books")
Exemple #11
0
class Posts(db.Model):
    __tablename__ = "posts"
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    userid = db.Column(db.Integer , db.ForeignKey("user.id") , nullable = False)
    title = db.Column(db.String(50) , default = 'My post')
    post = db.Column(db.Text, nullable=False)
    likes = db.Column(db.Integer, default=0)
    regdate = db.Column(db.DateTime ,nullable = False )
Exemple #12
0
class Review(db.Model):
    book_id = db.Column(db.String(25),
                        db.ForeignKey('book.id'),
                        primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    username = db.Column(db.String(25), nullable=False)
    bookname = db.Column(db.String(50), nullable=False)
    timestamp = db.Column(db.DateTime, default=datetime.utcnow)
    review = db.Column(db.Text)
    rating = db.Column(db.Float)

    books = db.relationship("Book", back_populates="reviews")
    users = db.relationship("User", back_populates="reviews")
Exemple #13
0
class File(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), unique=True, nullable=False)
    upload_date = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    update_time = db.Column(db.DateTime, nullable=True)
    description = db.Column(db.String(100))
    user_id = db.Column(db.String(50),
                        db.ForeignKey('user.email'),
                        nullable=False)

    def __repr__(self):
        return f"File('{self.name}', '{self.upload_date}')"
Exemple #14
0
class LikedPosts(UserMixin, db.Model):
    __tablename__ = "liked_post"
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    post_id = db.Column(db.Integer, db.ForeignKey("posts.id"), nullable=False)
Exemple #15
0
class User(db.Model, UserMixin):

    id = db.Column(db.Integer, primary_key = True)
    name = db.Column(db.String(10), unique = True,  nullable = False)
    email = db.Column(db.String(120), unique = True,  nullable = False)
    password = db.Column(db.String(60), nullable = False)
Exemple #16
0
class Question(db.Model, UserMixin):
    
    id = db.Column(db.Integer, primary_key = True)
    Question = db.Column(db.String(10),   nullable = False)
    Submitted_by = db.Column(db.String(60), nullable = False)