Add pages to Book

This commit is contained in:
2022-07-21 01:08:22 +03:00
parent dac9b94680
commit 22d4aa006d
2 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
"""empty message
Revision ID: b44117a41999
Revises: 08193b547a80
Create Date: 2021-11-18 18:25:06.921287
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql.schema import UniqueConstraint
# revision identifiers, used by Alembic.
revision = "b44117a41999"
down_revision = "08193b547a80"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("books", sa.Column("pages", sa.Integer(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("books", "pages")
# ### end Alembic commands ###

View File

@@ -1,4 +1,5 @@
from datetime import date from datetime import date
from typing import Optional
import ormar import ormar
from sqlalchemy import text from sqlalchemy import text
@@ -150,6 +151,7 @@ class Book(ormar.Model):
is_deleted: bool = ormar.Boolean( is_deleted: bool = ormar.Boolean(
default=False, server_default=text("false"), nullable=False default=False, server_default=text("false"), nullable=False
) )
pages: Optional[int] = ormar.Integer(minimum=0, nullable=True) # type: ignore
authors = ormar.ManyToMany(Author, through=BookAuthors) authors = ormar.ManyToMany(Author, through=BookAuthors)
translators = ormar.ManyToMany( translators = ormar.ManyToMany(