25 lines
748 B
Python
25 lines
748 B
Python
from typing import TYPE_CHECKING, List, Tuple
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from .account_base import AccountBase
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
# if the target of the relationship is in another module
|
|
# that cannot normally be imported at runtime
|
|
from .product import Product
|
|
|
|
|
|
class Account(AccountBase):
|
|
__mapper_args__ = {"polymorphic_identity": ""} # type: ignore
|
|
|
|
products: List["Product"] = relationship(
|
|
"Product", primaryjoin="Account.id==Product.account_id", back_populates="account"
|
|
)
|
|
|
|
def can_delete(self, advanced_delete: bool) -> Tuple[bool, str]:
|
|
if len(self.products) > 0:
|
|
return False, "Account has products"
|
|
return super(Account, self).can_delete(advanced_delete)
|