23 lines
767 B
Python
23 lines
767 B
Python
from sqlalchemy import Column, Integer, String, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from crudkit.core.base import CRUDMixin, Base
|
|
|
|
class Dbref(Base, CRUDMixin):
|
|
__tablename__ = "dbref"
|
|
|
|
type = Column(String, nullable=False)
|
|
name = Column(String, nullable=False)
|
|
|
|
owner_id = Column(Integer, ForeignKey("dbref.id"))
|
|
location_id = Column(Integer, ForeignKey("dbref.id"))
|
|
|
|
owner = relationship("Dbref", remote_side=[CRUDMixin.id], foreign_keys=[owner_id])
|
|
location = relationship("Dbref", remote_side=[CRUDMixin.id], foreign_keys=[location_id])
|
|
|
|
__mapper_args__ = {
|
|
"polymorphic_on": type,
|
|
"polymorphic_identity": "dbref"
|
|
}
|
|
|
|
def __str__(self):
|
|
return f"#{self.id} ({self.type}): {self.name}"
|