Compare commits
No commits in common. "5dde0468d000fa9b20f5d8963b52ecb4b23e1b2a" and "765b939998fd973ea1904ec1dcdce4dc97e9e3d2" have entirely different histories.
5dde0468d0
...
765b939998
1
.gitignore
vendored
1
.gitignore
vendored
@ -160,4 +160,3 @@ cython_debug/
|
|||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
*.bak
|
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
from sqlalchemy import Column, Integer, String
|
from sqlalchemy import Column, Integer, VARCHAR
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
from .book import Book
|
|
||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
class Author(Base):
|
class Author(Base):
|
||||||
__tablename__ = 'author'
|
__tablename__ = "author"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
id = Column(Integer, primary_key=True)
|
||||||
first_name = Column(String(50), nullable=False)
|
first_name = Column(VARCHAR(length=50))
|
||||||
last_name = Column(String(50), nullable=False)
|
last_name = Column(VARCHAR(length=50))
|
||||||
|
|
||||||
books = relationship('Book', back_populates='author')
|
|
@ -1,28 +0,0 @@
|
|||||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum
|
|
||||||
from sqlalchemy.orm import relationship
|
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
from .author import Author
|
|
||||||
from .book_category import BookCategory
|
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
|
|
||||||
class Book(Base):
|
|
||||||
__tablename__ = 'book'
|
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
||||||
author_id = Column(Integer, ForeignKey(
|
|
||||||
'author.id'), nullable=False, index=True)
|
|
||||||
title = Column(String(100), nullable=False)
|
|
||||||
description = Column(Text, nullable=False)
|
|
||||||
year_published = Column(String(4), nullable=False)
|
|
||||||
isbn = Column(String(13), nullable=False, unique=True)
|
|
||||||
status = Column(Enum('available', 'borrowed', 'reserved'),
|
|
||||||
nullable=False, default='available')
|
|
||||||
created_at = Column(TIMESTAMP, nullable=True, default="CURRENT_TIMESTAMP")
|
|
||||||
|
|
||||||
author = relationship('Author', back_populates='books')
|
|
||||||
# loans = relationship('Loan', back_populates='book')
|
|
||||||
categories = relationship(
|
|
||||||
'BookCategory', secondary='book_category_link', back_populates='books')
|
|
@ -1,19 +0,0 @@
|
|||||||
from .book import Book
|
|
||||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum
|
|
||||||
from sqlalchemy.orm import relationship
|
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
|
|
||||||
class BookCategory(Base):
|
|
||||||
__tablename__ = 'book_category'
|
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
||||||
parent_category_id = Column(Integer, ForeignKey(
|
|
||||||
'book_category.id'), nullable=True, index=True)
|
|
||||||
name = Column(String(100), nullable=False, unique=True)
|
|
||||||
|
|
||||||
parent_category = relationship('BookCategory', remote_side=[id])
|
|
||||||
books = relationship(
|
|
||||||
'Book', secondary='book_category_link', back_populates='categories')
|
|
@ -1,10 +0,0 @@
|
|||||||
from sqlalchemy import Column, Integer, ForeignKey
|
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
class BookCategoryLink(Base):
|
|
||||||
__tablename__ = 'book_category_link'
|
|
||||||
|
|
||||||
book_id = Column(Integer, ForeignKey('book.id'), primary_key=True, index=True)
|
|
||||||
book_category_id = Column(Integer, ForeignKey('book_category.id'), primary_key=True, index=True)
|
|
Loading…
x
Reference in New Issue
Block a user