29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
|
"""This module defines the SQL data model for todo items."""
|
||
|
|
||
|
import enum
|
||
|
|
||
|
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, Date, Enum, CheckConstraint, Boolean
|
||
|
from sqlalchemy.sql.functions import now
|
||
|
from sqlalchemy.orm import relationship
|
||
|
|
||
|
from todo.database.engine import Base
|
||
|
from todo.models.users import User
|
||
|
|
||
|
|
||
|
class TodoItem(Base):
|
||
|
"""Model for the todo_items table."""
|
||
|
|
||
|
__tablename__ = "todo_items"
|
||
|
|
||
|
id = Column('id', Integer, primary_key=True, autoincrement=True, index=True)
|
||
|
title = Column('title', String, nullable=False)
|
||
|
description = Column('description', String, nullable=False)
|
||
|
done = Column('done', Boolean, nullable=False, default=False, index=True)
|
||
|
|
||
|
created = Column('created', DateTime(timezone=True), nullable=False, server_default=now())
|
||
|
updated = Column('updated', DateTime(timezone=True), nullable=False, server_default=now(), onupdate=now())
|
||
|
finished = Column('finished', DateTime(timezone=True), nullable=True, default=None)
|
||
|
|
||
|
user_id = Column('user_id', Integer, ForeignKey('users.id', ondelete="CASCADE"), nullable=False)
|
||
|
user = relationship(User, back_populates="todo_items", uselist=False)
|