More fixes to models.
This commit is contained in:
parent
49e6ab38b9
commit
e1bb07717b
11 changed files with 40 additions and 14 deletions
|
|
@ -2,6 +2,7 @@ from typing import List, Optional
|
|||
|
||||
from sqlalchemy import Boolean, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -12,7 +13,7 @@ class Area(Base, CRUDMixin):
|
|||
|
||||
rooms: Mapped[List['Room']] = relationship('Room', back_populates='area')
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False)
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Area(id={self.id}, name={repr(self.name)})>"
|
||||
|
|
@ -2,6 +2,7 @@ from typing import List
|
|||
|
||||
from sqlalchemy import Boolean, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -12,7 +13,7 @@ class Brand(Base, CRUDMixin):
|
|||
|
||||
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='brand')
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False)
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Brand(id={self.id}, name={repr(self.name)})>"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import Unicode
|
||||
from sqlalchemy import Boolean, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -12,5 +13,7 @@ class DeviceType(Base, CRUDMixin):
|
|||
|
||||
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='device_type')
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Item(id={self.id}, description={repr(self.description)})>"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import DateTime, Unicode, func
|
||||
from sqlalchemy import Boolean, DateTime, Unicode, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -16,5 +17,7 @@ class Image(Base, CRUDMixin):
|
|||
user: Mapped[Optional['User']] = relationship('User', back_populates='image')
|
||||
# worklogs: Mapped[List['WorkLog']] = relationship('WorkLog', back_populates='images')
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Image(id={self.id}, filename={self.filename})>"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from typing import List, Optional
|
|||
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, Integer, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ class Inventory(Base, CRUDMixin):
|
|||
condition: Mapped[str] = mapped_column(Unicode(255))
|
||||
model: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
notes: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
shared: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
shared: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
timestamp: Mapped[DateTime] = mapped_column(DateTime)
|
||||
|
||||
brand: Mapped[Optional['Brand']] = relationship('Brand', back_populates='inventory')
|
||||
|
|
@ -35,6 +36,8 @@ class Inventory(Base, CRUDMixin):
|
|||
|
||||
work_logs: Mapped[Optional[List['WorkLog']]] = relationship('WorkLog', back_populates='work_item')
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self):
|
||||
parts = [f"id={self.id}"]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
from typing import List, Optional, TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey, Integer, Unicode
|
||||
from sqlalchemy import Boolean, ForeignKey, Integer, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -21,7 +22,9 @@ class Room(Base, CRUDMixin):
|
|||
users: Mapped[List['User']] = relationship('User', back_populates='location')
|
||||
|
||||
room_function: Mapped[Optional['RoomFunction']] = relationship('RoomFunction', back_populates='rooms')
|
||||
room_function_id: Mapped[Optional[int]] = mapped_column('function_id', Integer, ForeignKey("room_function.id"), nullable=True, index=True)
|
||||
function_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("room_function.id"), nullable=True, index=True)
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Room(id={self.id}, name={repr(self.name)}, area={repr(self.area.name)}, function={repr(self.room_function.description)})>"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import Unicode
|
||||
from sqlalchemy import Boolean, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -12,5 +13,7 @@ class RoomFunction(Base, CRUDMixin):
|
|||
|
||||
rooms: Mapped[List['Room']] = relationship('Room', back_populates='room_function')
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self):
|
||||
return f"<RoomFunction(id={self.id}, description={repr(self.description)})>"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from typing import List, Optional, TYPE_CHECKING
|
|||
|
||||
from sqlalchemy import Boolean, Integer, ForeignKey, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -15,8 +16,8 @@ class User(Base, CRUDMixin):
|
|||
last_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||
title: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||
|
||||
active: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=False, default=False)
|
||||
staff: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=False, default=False)
|
||||
active: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=False, default=True, server_default=sql.true())
|
||||
staff: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
image: Mapped[Optional['Image']] = relationship('Image', back_populates='user', passive_deletes=True)
|
||||
image_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("images.id", ondelete="SET NULL"), nullable=True, index=True)
|
||||
|
|
@ -32,5 +33,7 @@ class User(Base, CRUDMixin):
|
|||
|
||||
work_logs: Mapped[Optional[List['WorkLog']]] = relationship('WorkLog', back_populates='contact')
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self):
|
||||
return f"<User(id={self.id}, first_name={repr(self.first_name)}, last_name={repr(self.last_name)})>"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from typing import List, Optional
|
|||
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ class WorkLog(Base, CRUDMixin):
|
|||
start_time: Mapped[Optional[DateTime]] = mapped_column(DateTime)
|
||||
end_time: Mapped[Optional[DateTime]] = mapped_column(DateTime)
|
||||
|
||||
complete: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=False, default=False)
|
||||
complete: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
contact: Mapped[Optional['User']] = relationship('User', back_populates='work_logs')
|
||||
contact_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
|
||||
|
|
@ -21,5 +22,7 @@ class WorkLog(Base, CRUDMixin):
|
|||
work_item: Mapped[Optional['Inventory']] = relationship('Inventory', back_populates='work_logs')
|
||||
work_item_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('inventory.id'), nullable=True, index=True)
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self):
|
||||
return f"<WorkLog(id={self.id}, contact={repr(self.contact.first_name)} {repr(self.contact.last_name)})>"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from sqlalchemy import DateTime, ForeignKey, Integer, UnicodeText, func
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, UnicodeText, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import expression as sql
|
||||
|
||||
from crudkit.core.base import Base, CRUDMixin
|
||||
|
||||
|
|
@ -12,6 +13,8 @@ class WorkNote(Base, CRUDMixin):
|
|||
work_log: Mapped['WorkLog'] = relationship('WorkLog', back_populates='updates')
|
||||
work_log_id: Mapped[int] = mapped_column(Integer, ForeignKey('work_log.id'))
|
||||
|
||||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self) -> str:
|
||||
preview = self.content[:30].replace("\n", " ") + "..." if len(self.content) > 30 else self.content
|
||||
return f"<WorkNote(id={self.id}), log_id={self.work_log_id}, ts={self.timestamp}, content={preview!r}>"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue