-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
27 lines (21 loc) · 937 Bytes
/
models.py
File metadata and controls
27 lines (21 loc) · 937 Bytes
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
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy import String, ForeignKey
from database import Base
from typing import List
# PostgreSQL table
class TasksModel(Base):
__tablename__ = 'tasks'
id: Mapped[int] = mapped_column(primary_key=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
task_title: Mapped[str]
is_completed: Mapped[bool] = mapped_column(default=False)
# Relationship with users table
users: Mapped["UsersModel"] = relationship(back_populates="tasks")
class UsersModel(Base):
__tablename__ = 'users'
id: Mapped[int] = mapped_column(primary_key=True)
username: Mapped[str]
email: Mapped[str] = mapped_column(unique=True)
hashed_password: Mapped[str] = mapped_column(String(length=1024))
# Relationship with tasks table
tasks: Mapped[List["TasksModel"]] = relationship(back_populates="users")