diff --git a/app/models.py b/app/models.py index 19c0355..bfdf4a0 100644 --- a/app/models.py +++ b/app/models.py @@ -1,6 +1,11 @@ from flask_login import UserMixin from . import db +# many-to-many books/tags +tags = db.Table('books_tags', + db.Column('id_tag', db.Integer, db.ForeignKey('tag.id'), primary_key=True), + db.Column('id_book', db.Integer, db.ForeignKey('book.id'), primary_key=True) + ) class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(100), unique=True, nullable=False) @@ -27,6 +32,8 @@ class Book(db.Model): editorial = db.relationship('Editorial', backref='books') genre = db.relationship('Genre', backref='books') + book_tags = db.relationship('Tag', secondary=tags, backref=db.backref('books', lazy='dynamic')) + class Author(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) @@ -48,12 +55,6 @@ class Genre(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), primary_key=True) -# many-to-many books/tags -tags = db.Table('books_tags', - db.Column('id_tag', db.Integer, db.ForeignKey('tag.id'), primary_key=True), - db.Column('id_book', db.Integer, db.ForeignKey('book.id'), primary_key=True) - ) - class Quotes(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) diff --git a/migrations/versions/0fdda1165133_.py b/migrations/versions/0fdda1165133_.py new file mode 100644 index 0000000..aca75b4 --- /dev/null +++ b/migrations/versions/0fdda1165133_.py @@ -0,0 +1,24 @@ +"""empty message + +Revision ID: 0fdda1165133 +Revises: a7e98095982b +Create Date: 2024-04-26 23:25:36.332371 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '0fdda1165133' +down_revision = 'a7e98095982b' +branch_labels = None +depends_on = None + + +def upgrade(): + pass + + +def downgrade(): + pass diff --git a/migrations/versions/__pycache__/0fdda1165133_.cpython-310.pyc b/migrations/versions/__pycache__/0fdda1165133_.cpython-310.pyc new file mode 100644 index 0000000..190debe Binary files /dev/null and b/migrations/versions/__pycache__/0fdda1165133_.cpython-310.pyc differ