|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- from __future__ import annotations
-
- from datetime import datetime
-
- from eloquent import Model # type: ignore
-
- from .config import DB
-
-
- class AnsweredFlag (Model):
- id: int
- answer_id: int
- platform: int
- answered: bool
-
- __timestamps__ = False
-
- @property
- def answer (
- self,
- ) -> Answer:
- return self.belongs_to (Answer)
-
-
- class Answer (Model):
- id: int
- query_id: int
- character: int
- content: str
- answer_type: int
- sent_at: datetime
-
- __timestamps__ = False
-
- @property
- def query (
- self,
- ) -> Query:
- return self.belongs_to (Query)
-
- def answered (
- self,
- platform: int,
- ) -> bool | None:
- answered_flag = (AnsweredFlag.where ('answer_id', self.id)
- .where ('platform', platform)
- .first ())
- if answered_flag is None:
- return None
- return answered_flag.answered
-
-
- class Query (Model):
- id: int
- user_id: int | None
- target_character: int
- content: str
- image_url: str | None
- query_type: int
- model: int
- sent_at: datetime
- answered: bool
-
- __timestamps__ = False
-
- @property
- def user (
- self,
- ) -> User:
- return self.belongs_to (User)
-
- @property
- def answer_histories (
- self,
- ) -> list[Answer]:
- return [x.answer for x in self.has_many (QueryAnswerHistory).get ()]
-
-
- class QueryAnswerHistory (Model):
- id: int
- query_id: int
- answer_id: int
-
- __timestamps__ = False
-
- @property
- def query (
- self,
- ) -> Query:
- return self.belongs_to (Query)
-
- @property
- def answer (
- self,
- ) -> Answer:
- return self.belongs_to (Answer)
-
-
- class User (Model):
- id: int
- platform: int
- code: str
- name: str
- icon: bytes
-
- __timestamps__ = False
|