28 lines
808 B
Python
28 lines
808 B
Python
|
|
from sqlalchemy import String, Text, ForeignKey
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column, declared_attr
|
||
|
|
|
||
|
|
from .base import Base, bidirectional_relationship
|
||
|
|
# noinspection PyProtectedMember
|
||
|
|
from .status import StatusForeignKey
|
||
|
|
from .user import Versioned
|
||
|
|
|
||
|
|
|
||
|
|
__all__ = ["Contact"]
|
||
|
|
|
||
|
|
class Contact(StatusForeignKey, Versioned, Base):
|
||
|
|
"""Contact"""
|
||
|
|
|
||
|
|
name: Mapped[str] = mapped_column(String(80), unique=True)
|
||
|
|
address: Mapped[str | None] = mapped_column(String(253))
|
||
|
|
notes: Mapped[str | None] = mapped_column(Text)
|
||
|
|
|
||
|
|
|
||
|
|
class ContactForeignKey:
|
||
|
|
"""Foreign Key Mixin for :py:class:`Contact`"""
|
||
|
|
|
||
|
|
contact_id: Mapped[int | None] = mapped_column(ForeignKey("contact.id"))
|
||
|
|
|
||
|
|
@declared_attr
|
||
|
|
def contact(cls) -> Mapped["Contact"]:
|
||
|
|
return bidirectional_relationship(cls, Contact)
|