28 lines
No EOL
851 B
Python
28 lines
No EOL
851 B
Python
from typing import List, Optional, TYPE_CHECKING
|
|
if TYPE_CHECKING:
|
|
from .inventory import Inventory
|
|
|
|
from sqlalchemy import Identity, Integer, Unicode
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from . import db
|
|
|
|
class Brand(db.Model):
|
|
__tablename__ = 'Brands'
|
|
|
|
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
|
name: Mapped[Optional[str]] = mapped_column("Brand", Unicode(255), nullable=True)
|
|
|
|
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='brand')
|
|
|
|
def __init__(self, name: Optional[str] = None):
|
|
self.name = name
|
|
|
|
def __repr__(self):
|
|
return f"<Brand(id={self.id}, name={repr(self.name)})>"
|
|
|
|
def serialize(self):
|
|
return {
|
|
'id': self.id,
|
|
'name': self.name
|
|
} |