Beispiel #1
0
class Category(db.Model):
    __tablename__ = 'categories'
    categoryId = db.Column(db.Integer, primary_key=True)
    categoryName = db.Column(db.String(25), unique=False)
    image_file = db.Column(db.String(20), nullable=False, default='default.png')
    parentCategory = db.Column(db.String(25), unique=False, nullable=True)
    createdBy = db.Column(db.Integer, db.ForeignKey('users.id'))
    category_questions = db.relationship('Question', backref='category_questions', lazy='joined')

    def __repr__(self):
        return str(self.categoryName)
Beispiel #2
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=False)
    username = db.Column(db.String(20), unique=True)
    email = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(256), unique=False)
    image_file = db.Column(db.String(20), nullable=False, default='default.png')
    categories = db.relationship('Category', backref='categories_created', lazy=True)
    statistics = db.relationship('Statistic', backref='quiz_results', lazy=True)
    questions = db.relationship('Question', backref='questions_added', lazy=True)
    interests = db.relationship('Category', secondary=user_interests, lazy='joined', backref='interests_checked')

    def __repr__(self):
        return str(self.name + " " + self.username)
Beispiel #3
0
class Question(db.Model):
    __tablename__ = 'questions'
    questionId = db.Column(db.Integer, primary_key=True)
    questionText = db.Column(db.String(100), nullable=False, unique=False)
    categoryId = db.Column(db.Integer, db.ForeignKey('categories.categoryId'))
    createdBy = db.Column(db.Integer, db.ForeignKey('users.id'))
    answers = db.relationship('Answer', backref='answers', lazy=True, uselist=False, cascade="all,delete")

    def serialize(self):
        return {"questionId": self.questionId,
                "question": self.questionText,
                "answer": self.answers.answerText
                }
Beispiel #4
0
class Answer(db.Model):
    __tablename__ = 'answers'
    answerId = db.Column(db.Integer, primary_key=True)
    answerText = db.Column(db.String(100), unique=False)
    questionId = db.Column(db.Integer, db.ForeignKey('questions.questionId', ondelete="CASCADE"), nullable=False,
                           unique=False)
Beispiel #5
0
from quizapp import db
from quizapp import login_manager
from flask_login import UserMixin


# Method for login sessions
@login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))


user_interests = db.Table('user_interests',
                          db.Column('username', db.String(20), db.ForeignKey('users.username'), primary_key=True),
                          db.Column('category', db.String(25), db.ForeignKey('categories.categoryName'),
                                    primary_key=True))


class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=False)
    username = db.Column(db.String(20), unique=True)
    email = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(256), unique=False)
    image_file = db.Column(db.String(20), nullable=False, default='default.png')
    categories = db.relationship('Category', backref='categories_created', lazy=True)
    statistics = db.relationship('Statistic', backref='quiz_results', lazy=True)
    questions = db.relationship('Question', backref='questions_added', lazy=True)
    interests = db.relationship('Category', secondary=user_interests, lazy='joined', backref='interests_checked')

    def __repr__(self):
Beispiel #6
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(30), unique=True)
    email = db.Column(db.String(40), nullable=False, unique=True)
    password = db.Column(db.String(100))
Beispiel #7
0
class Answer(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    answer = db.Column(db.String(20),nullable=False)
    isCorrect = db.Column(db.Boolean,default=False)
    questions = db.Column(db.Integer, db.ForeignKey('question.id'),nullable=False)
Beispiel #8
0
class Question(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    question = db.Column(db.String(200),nullable=False)
    answers = db.relationship("Answer",backref='author',lazy=True)