18 lines
740 B
Python
18 lines
740 B
Python
from sqlalchemy import Column, String, Integer, ForeignKey, DateTime
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from core.database import Base
|
|
import uuid
|
|
|
|
class Book(Base):
|
|
__tablename__ = "books"
|
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
title = Column(String, nullable=False)
|
|
author = Column(String, nullable=False)
|
|
description = Column(String)
|
|
page_count = Column(Integer)
|
|
published_date = Column(DateTime)
|
|
genre_id = Column(String, ForeignKey("genres.id"))
|
|
genre = relationship("Genre", back_populates="books")
|
|
created_at = Column(DateTime, default=func.now())
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now()) |