2019-12-12 23:02:49 +00:00
|
|
|
from typing import *
|
2019-11-29 20:18:01 +00:00
|
|
|
from sqlalchemy import *
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from sqlalchemy.ext.declarative import declared_attr
|
|
|
|
|
2019-12-12 23:02:49 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from royalnet.backpack.tables import User
|
|
|
|
|
2019-11-29 20:18:01 +00:00
|
|
|
|
|
|
|
class KeiPerson:
|
|
|
|
__tablename__ = "keipeople"
|
|
|
|
|
2019-11-29 23:45:41 +00:00
|
|
|
@declared_attr
|
2019-12-12 23:02:49 +00:00
|
|
|
def kpid(self) -> str:
|
2019-11-29 23:45:41 +00:00
|
|
|
return Column(String, primary_key=True)
|
|
|
|
|
2019-11-29 20:18:01 +00:00
|
|
|
@declared_attr
|
2019-12-12 23:02:49 +00:00
|
|
|
def user_id(self) -> Optional[int]:
|
2019-11-29 23:45:41 +00:00
|
|
|
return Column(Integer, ForeignKey("users.uid"))
|
2019-11-29 20:18:01 +00:00
|
|
|
|
|
|
|
@declared_attr
|
2019-12-13 01:48:16 +00:00
|
|
|
def user(self) -> Optional["User"]:
|
2019-11-29 20:18:01 +00:00
|
|
|
return relationship("User", foreign_keys=self.user_id, backref="kei_people")
|
|
|
|
|
2019-12-12 23:02:49 +00:00
|
|
|
@declared_attr
|
|
|
|
def name(self) -> Optional[str]:
|
|
|
|
return Column(String)
|
|
|
|
|
2019-11-29 23:45:41 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return f"<{self.__class__.__qualname__} {self.kpid}{' ' + self.user.username if self.user is not None else ''}>"
|
2019-12-09 23:39:33 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.user.username if self.user is not None else self.kpid
|