from database import database

class AnswerModel(database.Model):
    __tablename__ = 'answers'

    answer_id = database.Column(database.Integer, primary_key=True, nullable=False)
    quiz_id = database.Column(database.Integer, database.ForeignKey('quizzes.quiz_id'), nullable=False)
    body = database.Column(database.String)
    is_correct = database.Column(database.Boolean)
    path_to_attachment = database.Column(database.String)
    is_selected = database.Column(database.Boolean)

    quiz = database.relationship('QuizModel')

    def __init__(self, answer_id, quiz_id, body, is_correct, path_to_attachment, is_selected):
        self.answer_id = answer_id
        self.quiz_id = quiz_id
        self.body = body
        self.is_correct = is_correct
        self.path_to_attachment = path_to_attachment
        self.is_selected = is_selected
    
    def json(self, getCorrectAnswers=False):
        answerJson = {
            'answer_id': self.answer_id,
            'quiz_id': self.quiz_id,
            'body': self.body,
            'path_to_attachment': self.path_to_attachment,
            'is_selected': self.is_selected,
        }

        if getCorrectAnswers: # the reason 'is_correct' is isolated is because during a test the data is stored in the browser's session storage, so during this time we don't want the correct answers to be visible to the user if they look in their browser's storage
            answerJson['is_correct'] = self.is_correct
        
        return answerJson

    def save_to_database(self):
        database.session.add(self)
        database.session.commit()

    def delete_from_database(self):
        database.session.delete(self)
        database.session.commit()

    @classmethod
    def find_by_id(cls, answer_id):
        return cls.query.filter_by(answer_id=answer_id).first()
99555c115cc6c6f7bf076cb5c7c18ee62c1b69a7
<mask token>


class AnswerModel(database.Model):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def json(self, getCorrectAnswers=False):
        answerJson = {'answer_id': self.answer_id, 'quiz_id': self.quiz_id,
            'body': self.body, 'path_to_attachment': self.
            path_to_attachment, 'is_selected': self.is_selected}
        if getCorrectAnswers:
            answerJson['is_correct'] = self.is_correct
        return answerJson

    def save_to_database(self):
        database.session.add(self)
        database.session.commit()
    <mask token>

    @classmethod
    def find_by_id(cls, answer_id):
        return cls.query.filter_by(answer_id=answer_id).first()

<mask token>


class AnswerModel(database.Model):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def __init__(self, answer_id, quiz_id, body, is_correct,
        path_to_attachment, is_selected):
        self.answer_id = answer_id
        self.quiz_id = quiz_id
        self.body = body
        self.is_correct = is_correct
        self.path_to_attachment = path_to_attachment
        self.is_selected = is_selected

    def json(self, getCorrectAnswers=False):
        answerJson = {'answer_id': self.answer_id, 'quiz_id': self.quiz_id,
            'body': self.body, 'path_to_attachment': self.
            path_to_attachment, 'is_selected': self.is_selected}
        if getCorrectAnswers:
            answerJson['is_correct'] = self.is_correct
        return answerJson

    def save_to_database(self):
        database.session.add(self)
        database.session.commit()

    def delete_from_database(self):
        database.session.delete(self)
        database.session.commit()

    @classmethod
    def find_by_id(cls, answer_id):
        return cls.query.filter_by(answer_id=answer_id).first()

<mask token>


class AnswerModel(database.Model):
    __tablename__ = 'answers'
    answer_id = database.Column(database.Integer, primary_key=True,
        nullable=False)
    quiz_id = database.Column(database.Integer, database.ForeignKey(
        'quizzes.quiz_id'), nullable=False)
    body = database.Column(database.String)
    is_correct = database.Column(database.Boolean)
    path_to_attachment = database.Column(database.String)
    is_selected = database.Column(database.Boolean)
    quiz = database.relationship('QuizModel')

    def __init__(self, answer_id, quiz_id, body, is_correct,
        path_to_attachment, is_selected):
        self.answer_id = answer_id
        self.quiz_id = quiz_id
        self.body = body
        self.is_correct = is_correct
        self.path_to_attachment = path_to_attachment
        self.is_selected = is_selected

    def json(self, getCorrectAnswers=False):
        answerJson = {'answer_id': self.answer_id, 'quiz_id': self.quiz_id,
            'body': self.body, 'path_to_attachment': self.
            path_to_attachment, 'is_selected': self.is_selected}
        if getCorrectAnswers:
            answerJson['is_correct'] = self.is_correct
        return answerJson

    def save_to_database(self):
        database.session.add(self)
        database.session.commit()

    def delete_from_database(self):
        database.session.delete(self)
        database.session.commit()

    @classmethod
    def find_by_id(cls, answer_id):
        return cls.query.filter_by(answer_id=answer_id).first()

from database import database


class AnswerModel(database.Model):
    __tablename__ = 'answers'
    answer_id = database.Column(database.Integer, primary_key=True,
        nullable=False)
    quiz_id = database.Column(database.Integer, database.ForeignKey(
        'quizzes.quiz_id'), nullable=False)
    body = database.Column(database.String)
    is_correct = database.Column(database.Boolean)
    path_to_attachment = database.Column(database.String)
    is_selected = database.Column(database.Boolean)
    quiz = database.relationship('QuizModel')

    def __init__(self, answer_id, quiz_id, body, is_correct,
        path_to_attachment, is_selected):
        self.answer_id = answer_id
        self.quiz_id = quiz_id
        self.body = body
        self.is_correct = is_correct
        self.path_to_attachment = path_to_attachment
        self.is_selected = is_selected

    def json(self, getCorrectAnswers=False):
        answerJson = {'answer_id': self.answer_id, 'quiz_id': self.quiz_id,
            'body': self.body, 'path_to_attachment': self.
            path_to_attachment, 'is_selected': self.is_selected}
        if getCorrectAnswers:
            answerJson['is_correct'] = self.is_correct
        return answerJson

    def save_to_database(self):
        database.session.add(self)
        database.session.commit()

    def delete_from_database(self):
        database.session.delete(self)
        database.session.commit()

    @classmethod
    def find_by_id(cls, answer_id):
        return cls.query.filter_by(answer_id=answer_id).first()

from database import database

class AnswerModel(database.Model):
    __tablename__ = 'answers'

    answer_id = database.Column(database.Integer, primary_key=True, nullable=False)
    quiz_id = database.Column(database.Integer, database.ForeignKey('quizzes.quiz_id'), nullable=False)
    body = database.Column(database.String)
    is_correct = database.Column(database.Boolean)
    path_to_attachment = database.Column(database.String)
    is_selected = database.Column(database.Boolean)

    quiz = database.relationship('QuizModel')

    def __init__(self, answer_id, quiz_id, body, is_correct, path_to_attachment, is_selected):
        self.answer_id = answer_id
        self.quiz_id = quiz_id
        self.body = body
        self.is_correct = is_correct
        self.path_to_attachment = path_to_attachment
        self.is_selected = is_selected
    
    def json(self, getCorrectAnswers=False):
        answerJson = {
            'answer_id': self.answer_id,
            'quiz_id': self.quiz_id,
            'body': self.body,
            'path_to_attachment': self.path_to_attachment,
            'is_selected': self.is_selected,
        }

        if getCorrectAnswers: # the reason 'is_correct' is isolated is because during a test the data is stored in the browser's session storage, so during this time we don't want the correct answers to be visible to the user if they look in their browser's storage
            answerJson['is_correct'] = self.is_correct
        
        return answerJson

    def save_to_database(self):
        database.session.add(self)
        database.session.commit()

    def delete_from_database(self):
        database.session.delete(self)
        database.session.commit()

    @classmethod
    def find_by_id(cls, answer_id):
        return cls.query.filter_by(answer_id=answer_id).first()