From 51edb750cee2375b3bda6cbef80528d9ed928d62 Mon Sep 17 00:00:00 2001 From: Djalim Simaila Date: Tue, 14 Mar 2023 19:00:14 +0100 Subject: [PATCH] fixed code to use new model --- truthinquiry/ext/database/dbutils.py | 2 +- truthinquiry/ext/database/models.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/truthinquiry/ext/database/dbutils.py b/truthinquiry/ext/database/dbutils.py index f1ce8ba..99ebe1a 100644 --- a/truthinquiry/ext/database/dbutils.py +++ b/truthinquiry/ext/database/dbutils.py @@ -49,7 +49,7 @@ def get_npc_random_answer(npc_id:int, qa_type:int) -> Answer : :param qa_type: the type of the question :return: an Answer object """ - answers = db.session.query(Answer).filter_by(QA_TYPE=qa_type,NPC_ID=npc_id.NPC_ID).all() + answers = db.session.query(Answer).filter_by(QUESTION_TYPE_ID=qa_type,NPC_ID=npc_id.NPC_ID).all() return random.choice(answers) def get_random_question(qa_type: int) -> QuestionType : diff --git a/truthinquiry/ext/database/models.py b/truthinquiry/ext/database/models.py index 4631aee..c53a8e7 100644 --- a/truthinquiry/ext/database/models.py +++ b/truthinquiry/ext/database/models.py @@ -78,7 +78,7 @@ class QuestionType(Base): """ __tablename__ = "T_QUESTION_TYPE" - QUESTION_TYPE_ID = Column(Integer, primary_key=True, comment="ID of this question type.") + QUESTION_TYPE_ID = Column(Integer, default=0, primary_key=True, comment="ID of this question type.") TEXT_LID = Column(Integer, ForeignKey("T_LOCALE.LID"), comment="Question text") LOCALE = relationship("Locale") @@ -100,7 +100,7 @@ class Answer(Base): """ __tablename__ = "T_ANSWER" - QUESTION_TYPE_ID = Column(Integer, ForeignKey("T_QUESTION_TYPE.QUESTION_TYPE_ID"), primary_key=True, comment="Question type ID") + QUESTION_TYPE_ID = Column(Integer,ForeignKey("T_QUESTION_TYPE.QUESTION_TYPE_ID"),primary_key=True, comment="Question type ID") NPC_ID = Column(Integer, ForeignKey("T_NPC.NPC_ID"), primary_key=True, comment="ID of the NPC that will say this answer") TEXT_LID = Column(Integer, ForeignKey("T_LOCALE.LID"), comment="Text of the answer") LOCALE = relationship("Locale") @@ -125,7 +125,7 @@ class Npc(Base): """ __tablename__ = "T_NPC" - NPC_ID = Column(Integer, primary_key=True, comment="ID of this Npc") + NPC_ID = Column(Integer, autoincrement=True, primary_key=True, comment="ID of this Npc") NAME_LID = Column(Integer, ForeignKey("T_LOCALE.LID"), comment="Name of this Npc") LOCALE = relationship("Locale") @@ -153,15 +153,13 @@ class Trait(Base): Desc = relationship("Locale",foreign_keys=[DESC_LID]) - def __init__(self, TRAIT_ID, NAME_LID): + def __init__(self, TRAIT_ID, NAME_LID, DESC_LID): self.TRAIT_ID = TRAIT_ID self.NAME_LID = NAME_LID + self.DESC_LID = DESC_LID def __str__(self) -> str: - return f"Trait(TRAIT_ID={self.TRAIT_ID}, NAME_LID={self.NAME_LID})" - - def __repr__(self) -> str: - return self.__str__() + return f"{self.TRAIT_ID} {self.NAME_LID}" class Reaction(Base):