AI ニジカ綜合
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 2.0 KiB

1 week ago
1 month ago
3 weeks ago
1 month ago
1 month ago
1 month ago
1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from __future__ import annotations
  2. from datetime import datetime
  3. from eloquent import Model # type: ignore
  4. from .config import DB
  5. class AnsweredFlag (Model):
  6. id: int
  7. answer_id: int
  8. platform: int
  9. answered: bool
  10. __timestamps__ = False
  11. @property
  12. def answer (
  13. self,
  14. ) -> Answer:
  15. return self.belongs_to (Answer)
  16. class Answer (Model):
  17. id: int
  18. query_id: int
  19. character: int
  20. content: str
  21. answer_type: int
  22. sent_at: datetime
  23. __timestamps__ = False
  24. @property
  25. def query (
  26. self,
  27. ) -> Query:
  28. return self.belongs_to (Query)
  29. def answered (
  30. self,
  31. platform: int,
  32. ) -> bool | None:
  33. answered_flag = (AnsweredFlag.where ('answer_id', self.id)
  34. .where ('platform', platform)
  35. .first ())
  36. if answered_flag is None:
  37. return None
  38. return answered_flag.answered
  39. class Query (Model):
  40. id: int
  41. user_id: int | None
  42. target_character: int
  43. content: str
  44. image_url: str | None
  45. query_type: int
  46. model: int
  47. sent_at: datetime
  48. answered: bool
  49. __timestamps__ = False
  50. @property
  51. def user (
  52. self,
  53. ) -> User:
  54. return self.belongs_to (User)
  55. @property
  56. def answer_histories (
  57. self,
  58. ) -> list[Answer]:
  59. return [x.answer for x in self.has_many (QueryAnswerHistory).get ()]
  60. class QueryAnswerHistory (Model):
  61. id: int
  62. query_id: int
  63. answer_id: int
  64. __timestamps__ = False
  65. @property
  66. def query (
  67. self,
  68. ) -> Query:
  69. return self.belongs_to (Query)
  70. @property
  71. def answer (
  72. self,
  73. ) -> Answer:
  74. return self.belongs_to (Answer)
  75. class User (Model):
  76. id: int
  77. platform: int
  78. code: str
  79. name: str
  80. icon: bytes
  81. __timestamps__ = False