1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00
royalnet/royalpack/tables/bios.py

34 lines
817 B
Python
Raw Permalink Normal View History

2019-11-11 08:56:08 +00:00
from sqlalchemy import Column, \
Integer, \
Text, \
ForeignKey
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declared_attr
class Bio:
__tablename__ = "bios"
@declared_attr
2020-02-11 18:53:18 +00:00
def user_id(self):
2019-11-11 08:56:08 +00:00
return Column(Integer, ForeignKey("users.uid"), primary_key=True)
@declared_attr
2020-02-11 18:53:18 +00:00
def user(self):
2019-11-11 08:56:08 +00:00
return relationship("User", backref=backref("bio", uselist=False))
@declared_attr
def contents(self):
return Column(Text, nullable=False, default="")
2020-02-11 18:53:18 +00:00
def json(self) -> dict:
return {
"contents": self.contents
}
2019-11-11 08:56:08 +00:00
def __repr__(self):
2020-02-11 18:53:18 +00:00
return f"<Bio of {self.user}>"
2019-11-11 08:56:08 +00:00
def __str__(self):
return self.contents