[FWA-5] Home Create and List
This commit is contained in:
@ -18,3 +18,6 @@ class SqlAlchemyBase(Model):
|
||||
@classmethod
|
||||
def normalize(cls, val: str) -> str:
|
||||
return unidecode(val).lower().strip()
|
||||
|
||||
class DeleteMixin:
|
||||
deleted_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
|
@ -4,30 +4,30 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from backend.db.models.guid import GUID
|
||||
|
||||
from .._model_base import SqlAlchemyBase
|
||||
from .._model_base import SqlAlchemyBase, DeleteMixin
|
||||
|
||||
class Houses(SqlAlchemyBase):
|
||||
class Houses(SqlAlchemyBase, DeleteMixin):
|
||||
__tablename__ = 'houses'
|
||||
|
||||
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate, index=True)
|
||||
icon: Mapped[str | None] = mapped_column(String, index=True, nullable=False)
|
||||
icon: Mapped[str | None] = mapped_column(String, nullable=False)
|
||||
name: Mapped[str | None] = mapped_column(String, index=True, nullable=False)
|
||||
address: Mapped[str | None] = mapped_column(String, index=True, nullable=False)
|
||||
address: Mapped[str | None] = mapped_column(String, nullable=False)
|
||||
|
||||
areas: Mapped[List["Areas"]] = relationship()
|
||||
areas: Mapped[List["Areas"]] = relationship("Areas", back_populates="house", cascade="all, delete", passive_deletes=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__class__.__name__}, name: {self.name}"
|
||||
|
||||
class Areas(SqlAlchemyBase):
|
||||
class Areas(SqlAlchemyBase, DeleteMixin):
|
||||
__tablename__ = 'areas'
|
||||
|
||||
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate, index=True)
|
||||
house_id: Mapped[GUID] = mapped_column(GUID, ForeignKey('houses.id'), index=True, nullable=False)
|
||||
house_id: Mapped[GUID] = mapped_column(GUID, ForeignKey('houses.id', ondelete='CASCADE'), nullable=False)
|
||||
name: Mapped[str | None] = mapped_column(String, index=True, nullable=False)
|
||||
desc: Mapped[str | None] = mapped_column(String, index=True, nullable=False)
|
||||
desc: Mapped[str | None] = mapped_column(String, nullable=False)
|
||||
|
||||
user: Mapped['Houses'] = relationship(back_populates="areas")
|
||||
house: Mapped['Houses'] = relationship(back_populates="areas")
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__class__.__name__}, name: {self.name}"
|
||||
|
@ -1,4 +1,6 @@
|
||||
from sqlalchemy import Boolean, String
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, String, DateTime
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from backend.db.models.guid import GUID
|
||||
@ -13,7 +15,7 @@ class Users(SqlAlchemyBase):
|
||||
password: Mapped[str | None] = mapped_column(String, index=True, nullable=False)
|
||||
name: Mapped[str | None] = mapped_column(String, index=True, nullable=True)
|
||||
is_admin: Mapped[bool | None] = mapped_column(Boolean, default=False)
|
||||
is_lock: Mapped[bool | None] = mapped_column(Boolean, default=False)
|
||||
is_lock: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__class__.__name__}, name: {self.name}, username: {self.username}"
|
||||
|
Reference in New Issue
Block a user