1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/keipack/tables/keipeople.py

34 lines
933 B
Python
Raw Permalink Normal View History

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):
2019-12-20 18:41:40 +00:00
return self.name if self.name is not None else self.kpid