-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.py
35 lines (27 loc) · 992 Bytes
/
types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
Base = declarative_base()
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True)
name = Column(String(30))
addresses = relationship(
"Inspiration", back_populates="user", cascade="all, delete-orphan"
)
def __repr__(self):
return f"User(id={self.id!r}, name={self.name!r})"
class Inspiration(Base):
__tablename__ = "inspiration"
id = Column(Integer, primary_key=True)
text = Column(String, nullable=False)
user_id = Column(Integer, ForeignKey("user.id"), nullable=True)
user = relationship("User", back_populates="inspirations")
def __repr__(self):
return f"Inspiration(id={self.id!r}, tex={self.text!r})"
Base.metadata.create_all()