[main] Slight changes to models to finally make them work
This commit is contained in:
parent
b22a0bb664
commit
1c860b70e8
@ -1,7 +1,10 @@
|
|||||||
|
from .base import Base
|
||||||
from .author import Author
|
from .author import Author
|
||||||
from .book_category import BookCategory
|
|
||||||
from .book import Book
|
from .book import Book
|
||||||
|
from .book_category import BookCategory
|
||||||
from .book_category_link import BookCategoryLink
|
from .book_category_link import BookCategoryLink
|
||||||
from .member import Member
|
from .member import Member
|
||||||
from .librarian import Librarian
|
from .librarian import Librarian
|
||||||
from .loan import Loan
|
from .loan import Loan
|
||||||
|
|
||||||
|
__all__ = ["Author", "Book", "BookCategory", "BookCategoryLink", "Member", "Librarian", "Loan"]
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, UniqueConstraint, func
|
from sqlalchemy import Column, Integer, String, TIMESTAMP, UniqueConstraint, func
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
Base = declarative_base()
|
from .base import Base
|
||||||
|
|
||||||
|
|
||||||
class Author(Base):
|
class Author(Base):
|
||||||
@ -13,3 +12,6 @@ class Author(Base):
|
|||||||
first_name = Column(String(50), nullable=False)
|
first_name = Column(String(50), nullable=False)
|
||||||
last_name = Column(String(50), nullable=False)
|
last_name = Column(String(50), nullable=False)
|
||||||
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
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
3
src/models/base.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
|
Base = declarative_base()
|
@ -2,12 +2,8 @@ import enum
|
|||||||
|
|
||||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
|
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
from .author import Author
|
from .base import Base
|
||||||
from .book_category import BookCategory
|
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
|
|
||||||
class BookStatusEnum(enum.Enum):
|
class BookStatusEnum(enum.Enum):
|
||||||
@ -15,6 +11,7 @@ class BookStatusEnum(enum.Enum):
|
|||||||
borrowed = 'borrowed'
|
borrowed = 'borrowed'
|
||||||
reserved = 'reserved'
|
reserved = 'reserved'
|
||||||
|
|
||||||
|
|
||||||
class Book(Base):
|
class Book(Base):
|
||||||
__tablename__ = 'book'
|
__tablename__ = 'book'
|
||||||
__table_args__ = (UniqueConstraint('isbn'),)
|
__table_args__ = (UniqueConstraint('isbn'),)
|
||||||
@ -29,4 +26,5 @@ class Book(Base):
|
|||||||
created_at = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
created_at = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||||
last_updated = 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')
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint, func
|
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint, func
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
|
from .base import Base
|
||||||
|
|
||||||
class BookCategory(Base):
|
class BookCategory(Base):
|
||||||
__tablename__ = 'book_category'
|
__tablename__ = 'book_category'
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
from sqlalchemy import Column, Integer, ForeignKey
|
from sqlalchemy import Column, Integer, ForeignKey
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
|
|
||||||
from .book import Book
|
from .book import Book
|
||||||
from .book_category import BookCategory
|
from .book_category import BookCategory
|
||||||
|
from .base import Base
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
class BookCategoryLink(Base):
|
class BookCategoryLink(Base):
|
||||||
__tablename__ = 'book_category_link'
|
__tablename__ = 'book_category_link'
|
||||||
|
@ -2,10 +2,8 @@ import enum
|
|||||||
|
|
||||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
|
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
|
from .base import Base
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
|
|
||||||
class LibrarianStatusEnum(enum.Enum):
|
class LibrarianStatusEnum(enum.Enum):
|
||||||
|
@ -2,14 +2,12 @@ import enum
|
|||||||
|
|
||||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float, func
|
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float, func
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
|
from .base import Base
|
||||||
from .book import Book
|
from .book import Book
|
||||||
from .member import Member
|
from .member import Member
|
||||||
from .librarian import Librarian
|
from .librarian import Librarian
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
|
|
||||||
class LoanStatusEnum(enum.Enum):
|
class LoanStatusEnum(enum.Enum):
|
||||||
borrowed = 'borrowed'
|
borrowed = 'borrowed'
|
||||||
|
@ -2,13 +2,14 @@ import enum
|
|||||||
|
|
||||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
|
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
from .base import Base
|
||||||
|
|
||||||
|
|
||||||
class MemberStatusEnum(enum.Enum):
|
class MemberStatusEnum(enum.Enum):
|
||||||
active = 'active'
|
active = 'active'
|
||||||
inactive = 'inactive'
|
inactive = 'inactive'
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
class Member(Base):
|
class Member(Base):
|
||||||
__tablename__ = 'member'
|
__tablename__ = 'member'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user