1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/keipack/tables/keimessages.py

37 lines
1 KiB
Python
Raw Normal View History

2019-12-12 23:02:49 +00:00
from typing import *
2019-11-29 23:45:41 +00:00
from sqlalchemy import *
2019-12-13 01:48:16 +00:00
from sqlalchemy.orm import relationship, backref
2019-11-29 23:45:41 +00:00
from sqlalchemy.ext.declarative import declared_attr
2019-12-12 23:02:49 +00:00
if TYPE_CHECKING:
from .keipeople import KeiPerson
2019-11-29 23:45:41 +00:00
class KeiMessage:
__tablename__ = "keimessages"
@declared_attr
2019-12-12 23:02:49 +00:00
def kmid(self) -> int:
2019-11-29 23:45:41 +00:00
return Column(Integer, primary_key=True)
@declared_attr
2019-12-12 23:02:49 +00:00
def kei_person_id(self) -> str:
2019-11-29 23:45:41 +00:00
return Column(String, ForeignKey("keipeople.kpid"), nullable=False)
@declared_attr
2019-12-12 23:02:49 +00:00
def kei_person(self) -> "KeiPerson":
2019-12-13 01:48:16 +00:00
return relationship("KeiPerson", foreign_keys=self.kei_person_id, backref=backref("kei_messages",
cascade="all, delete-orphan"))
2019-11-29 23:45:41 +00:00
2019-12-10 01:24:58 +00:00
@declared_attr
2019-12-12 23:02:49 +00:00
def previous(self) -> Optional[str]:
2019-12-10 01:24:58 +00:00
return Column(String)
2019-11-29 23:45:41 +00:00
@declared_attr
2019-12-12 23:02:49 +00:00
def message(self) -> str:
2019-11-29 23:45:41 +00:00
return Column(String, nullable=False)
def __repr__(self):
return f"<{self.__class__.__qualname__} '{self.message}'>"