2023-05-21 01:50:44 +01:00
|
|
|
"""This module defines the SQL data model for todo items."""
|
|
|
|
|
2023-05-30 15:27:29 +01:00
|
|
|
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, Boolean
|
2023-05-21 01:50:44 +01:00
|
|
|
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)
|
2023-05-22 12:44:10 +01:00
|
|
|
title = Column('title', String, nullable=False, index=True)
|
2023-05-21 01:50:44 +01:00
|
|
|
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())
|
2023-05-22 12:44:10 +01:00
|
|
|
updated = Column('updated', DateTime(timezone=True), nullable=False, server_default=now(), onupdate=now(), index=True)
|
2023-05-21 01:50:44 +01:00
|
|
|
finished = Column('finished', DateTime(timezone=True), nullable=True, default=None)
|
|
|
|
|
2023-05-22 12:44:10 +01:00
|
|
|
user_id = Column('user_id', Integer, ForeignKey('users.id', ondelete="CASCADE"), nullable=False, index=True)
|
2023-05-21 01:50:44 +01:00
|
|
|
user = relationship(User, back_populates="todo_items", uselist=False)
|