open-law/app/models/book_contributor.py

27 lines
668 B
Python
Raw Normal View History

2023-04-21 12:58:47 +00:00
from enum import IntEnum
from app import db
from app.models.utils import BaseModel
class BookContributor(BaseModel):
__tablename__ = "book_contributors"
class Roles(IntEnum):
2023-04-24 15:01:36 +00:00
UNKNOWN = 0
2023-04-21 12:58:47 +00:00
MODERATOR = 1
EDITOR = 2
role = db.Column(db.Enum(Roles), default=Roles.MODERATOR)
# Foreign keys
user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
book_id = db.Column(db.Integer, db.ForeignKey("books.id"))
# Relationships
user = db.relationship("User", viewonly=True)
book = db.relationship("Book", viewonly=True)
def __repr__(self):
2023-04-25 11:24:04 +00:00
return f"<{self.id}: u:{self.user_id} b:{self.book_id}>"