1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/royalpack/tables/bios.py
2020-02-11 19:53:18 +01:00

33 lines
817 B
Python

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
def user_id(self):
return Column(Integer, ForeignKey("users.uid"), primary_key=True)
@declared_attr
def user(self):
return relationship("User", backref=backref("bio", uselist=False))
@declared_attr
def contents(self):
return Column(Text, nullable=False, default="")
def json(self) -> dict:
return {
"contents": self.contents
}
def __repr__(self):
return f"<Bio of {self.user}>"
def __str__(self):
return self.contents