2023-04-21 13:13:43 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2023-04-21 12:58:47 +00:00
|
|
|
from app import db
|
|
|
|
from app.models.utils import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
class BookVersion(BaseModel):
|
|
|
|
__tablename__ = "book_versions"
|
|
|
|
|
|
|
|
# need to redeclare id to use it in the derivative relationship
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
semver = db.Column(db.String(1024), unique=False, nullable=False)
|
|
|
|
exported = db.Column(db.Boolean, default=False)
|
2023-04-21 13:13:43 +00:00
|
|
|
updated_at = db.Column(db.DateTime, default=datetime.now)
|
2023-04-21 12:58:47 +00:00
|
|
|
|
|
|
|
# Foreign keys
|
|
|
|
derivative_id = db.Column(db.Integer, db.ForeignKey("book_versions.id"))
|
|
|
|
book_id = db.Column(db.Integer, db.ForeignKey("books.id"))
|
|
|
|
|
|
|
|
# Relationships
|
|
|
|
book = db.relationship("Book", viewonly=True)
|
|
|
|
derivative = db.relationship("BookVersion", remote_side=[id])
|
2023-04-21 14:17:31 +00:00
|
|
|
sections = db.relationship("Section", viewonly=True)
|
2023-04-24 14:59:50 +00:00
|
|
|
collections = db.relationship("Collection", viewonly=True)
|
2023-04-21 12:58:47 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"<{self.id}: {self.semver}>"
|