2023-02-06 18:43:12 -09:00
|
|
|
from typing import TYPE_CHECKING, Optional
|
|
|
|
|
|
|
|
from sqlalchemy import Boolean, ForeignKey, Integer, String, orm
|
|
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
2021-08-31 14:39:29 -08:00
|
|
|
|
2021-09-04 12:28:49 -08:00
|
|
|
from .._model_base import BaseMixins, SqlAlchemyBase
|
2024-07-08 16:12:20 -05:00
|
|
|
from .._model_utils import guid
|
|
|
|
from .._model_utils.auto_init import auto_init
|
2021-09-04 12:28:49 -08:00
|
|
|
from ..recipe.category import Category, cookbooks_to_categories
|
2022-04-01 09:50:31 -08:00
|
|
|
from ..recipe.tag import Tag, cookbooks_to_tags
|
|
|
|
from ..recipe.tool import Tool, cookbooks_to_tools
|
2021-08-31 14:39:29 -08:00
|
|
|
|
2023-02-06 18:43:12 -09:00
|
|
|
if TYPE_CHECKING:
|
2024-07-08 16:12:20 -05:00
|
|
|
from .group import Group
|
2023-02-06 18:43:12 -09:00
|
|
|
|
2021-08-31 14:39:29 -08:00
|
|
|
|
|
|
|
class CookBook(SqlAlchemyBase, BaseMixins):
|
|
|
|
__tablename__ = "cookbooks"
|
2023-02-06 18:43:12 -09:00
|
|
|
id: Mapped[guid.GUID] = mapped_column(guid.GUID, primary_key=True, default=guid.GUID.generate)
|
|
|
|
position: Mapped[int] = mapped_column(Integer, nullable=False, default=1)
|
2022-01-13 13:06:52 -09:00
|
|
|
|
2023-02-11 20:40:53 +01:00
|
|
|
group_id: Mapped[guid.GUID | None] = mapped_column(guid.GUID, ForeignKey("groups.id"), index=True)
|
2023-02-06 18:43:12 -09:00
|
|
|
group: Mapped[Optional["Group"]] = orm.relationship("Group", back_populates="cookbooks")
|
2022-04-01 09:50:31 -08:00
|
|
|
|
2023-02-06 18:43:12 -09:00
|
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
2023-02-11 20:40:53 +01:00
|
|
|
slug: Mapped[str] = mapped_column(String, nullable=False, index=True)
|
2023-02-06 18:43:12 -09:00
|
|
|
description: Mapped[str | None] = mapped_column(String, default="")
|
|
|
|
public: Mapped[str | None] = mapped_column(Boolean, default=False)
|
2022-01-13 13:06:52 -09:00
|
|
|
|
2023-02-06 18:43:12 -09:00
|
|
|
categories: Mapped[list[Category]] = orm.relationship(
|
|
|
|
Category, secondary=cookbooks_to_categories, single_parent=True
|
|
|
|
)
|
|
|
|
require_all_categories: Mapped[bool | None] = mapped_column(Boolean, default=True)
|
2022-04-03 16:32:58 -08:00
|
|
|
|
2023-02-06 18:43:12 -09:00
|
|
|
tags: Mapped[list[Tag]] = orm.relationship(Tag, secondary=cookbooks_to_tags, single_parent=True)
|
|
|
|
require_all_tags: Mapped[bool | None] = mapped_column(Boolean, default=True)
|
2022-04-03 16:32:58 -08:00
|
|
|
|
2023-02-06 18:43:12 -09:00
|
|
|
tools: Mapped[list[Tool]] = orm.relationship(Tool, secondary=cookbooks_to_tools, single_parent=True)
|
|
|
|
require_all_tools: Mapped[bool | None] = mapped_column(Boolean, default=True)
|
2021-08-31 14:39:29 -08:00
|
|
|
|
|
|
|
@auto_init()
|
|
|
|
def __init__(self, **_) -> None:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def update(self, *args, **kwarg):
|
|
|
|
self.__init__(*args, **kwarg)
|