[main] Slight changes to models to finally make them work

This commit is contained in:
Thastertyn 2025-01-07 15:25:01 +01:00
parent b22a0bb664
commit 1c860b70e8
9 changed files with 36 additions and 38 deletions

View File

@ -1,7 +1,10 @@
from .base import Base
from .author import Author
from .book_category import BookCategory
from .book import Book
from .book_category import BookCategory
from .book_category_link import BookCategoryLink
from .member import Member
from .librarian import Librarian
from .loan import Loan
__all__ = ["Author", "Book", "BookCategory", "BookCategoryLink", "Member", "Librarian", "Loan"]

View File

@ -1,8 +1,7 @@
from sqlalchemy import Column, Integer, String, TIMESTAMP, UniqueConstraint, func
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
from .base import Base
class Author(Base):
@ -13,3 +12,6 @@ class Author(Base):
first_name = Column(String(50), nullable=False)
last_name = Column(String(50), nullable=False)
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
# Reference 'Book' as a string to avoid direct import
books = relationship('Book', back_populates='author')

3
src/models/base.py Normal file
View File

@ -0,0 +1,3 @@
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

View File

@ -2,12 +2,8 @@ import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from .author import Author
from .book_category import BookCategory
Base = declarative_base()
from .base import Base
class BookStatusEnum(enum.Enum):
@ -15,6 +11,7 @@ class BookStatusEnum(enum.Enum):
borrowed = 'borrowed'
reserved = 'reserved'
class Book(Base):
__tablename__ = 'book'
__table_args__ = (UniqueConstraint('isbn'),)
@ -29,4 +26,5 @@ class Book(Base):
created_at = Column(TIMESTAMP, nullable=False, server_default=func.now())
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
author = relationship('Author', backref='books')
# Reference 'Author' as a string to avoid direct import
author = relationship('Author', back_populates='books')

View File

@ -1,9 +1,7 @@
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint, func
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
from .base import Base
class BookCategory(Base):
__tablename__ = 'book_category'

View File

@ -1,12 +1,9 @@
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from .book import Book
from .book_category import BookCategory
Base = declarative_base()
from .base import Base
class BookCategoryLink(Base):
__tablename__ = 'book_category_link'

View File

@ -2,10 +2,8 @@ import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
from .base import Base
class LibrarianStatusEnum(enum.Enum):

View File

@ -2,14 +2,12 @@ import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float, func
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from .base import Base
from .book import Book
from .member import Member
from .librarian import Librarian
Base = declarative_base()
class LoanStatusEnum(enum.Enum):
borrowed = 'borrowed'

View File

@ -2,13 +2,14 @@ import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from .base import Base
class MemberStatusEnum(enum.Enum):
active = 'active'
inactive = 'inactive'
Base = declarative_base()
class Member(Base):
__tablename__ = 'member'