website-practice/backend/app/models.py

36 lines
933 B
Python

"""
Модуль, описывающий модели для базы данных.
"""
from sqlalchemy import Column, DateTime, Integer, String, Text, func
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
"""
Base model for all tables in the database.
Fields:
updated (Mapped[DateTime]): Update time of the object.
created (Mapped[DateTime]): Creation time of the object.
"""
updated: Mapped[DateTime] = mapped_column(
DateTime,
default=func.now(),
onupdate=func.now(),
nullable=False,
)
created: Mapped[DateTime] = mapped_column(
DateTime,
default=func.now(),
nullable=False,
)
class Item(Base):
__tablename__ = "items"
id = Column(Integer, primary_key=True, index=True)
title = Column(String(200), nullable=False)
description = Column(Text, nullable=True)