feat: Add Book model
This commit is contained in:
parent
f987431b99
commit
953446bd63
21
models/book.py
Normal file
21
models/book.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from sqlalchemy import Column, String, Integer, DateTime, ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
|
from core.database import Base
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
class Book(Base):
|
||||||
|
__tablename__ = "books"
|
||||||
|
|
||||||
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
|
title = Column(String, nullable=False)
|
||||||
|
author = Column(String, nullable=False)
|
||||||
|
description = Column(String, nullable=True)
|
||||||
|
page_count = Column(Integer, nullable=False)
|
||||||
|
genre = Column(String, nullable=False)
|
||||||
|
publisher_id = Column(UUID(as_uuid=True), ForeignKey("publishers.id"), nullable=False)
|
||||||
|
|
||||||
|
publisher = relationship("Publisher", back_populates="books")
|
||||||
|
created_at = Column(DateTime, default=func.now())
|
||||||
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
Loading…
x
Reference in New Issue
Block a user