Refactor model imports and add nullable indices for improved database performance and clarity
This commit is contained in:
parent
704638d07a
commit
dab23009c1
5 changed files with 43 additions and 43 deletions
|
@ -1,6 +1,6 @@
|
|||
from typing import Any, List, Optional, TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from .inventory import Inventory
|
||||
from .inventory import Inventory
|
||||
from .rooms import Room
|
||||
from .work_log import WorkLog
|
||||
from .image import Image
|
||||
|
@ -19,9 +19,9 @@ class User(db.Model, ImageAttachable):
|
|||
active: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||
last_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||
first_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||
location_id: Mapped[Optional[int]] = mapped_column(ForeignKey("rooms.id"), nullable=True)
|
||||
supervisor_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"))
|
||||
image_id: Mapped[Optional[int]] = mapped_column(ForeignKey('images.id', ondelete='SET NULL'), nullable=True)
|
||||
location_id: Mapped[Optional[int]] = mapped_column(ForeignKey("rooms.id"), nullable=True, index=True)
|
||||
supervisor_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
|
||||
image_id: Mapped[Optional[int]] = mapped_column(ForeignKey('images.id', ondelete='SET NULL'), nullable=True, index=True)
|
||||
|
||||
supervisor: Mapped[Optional['User']] = relationship('User', remote_side='User.id', back_populates='subordinates')
|
||||
subordinates: Mapped[List['User']] = relationship('User', back_populates='supervisor')
|
||||
|
@ -33,7 +33,7 @@ class User(db.Model, ImageAttachable):
|
|||
@property
|
||||
def full_name(self) -> str:
|
||||
return f"{self.first_name or ''} {self.last_name or ''}".strip()
|
||||
|
||||
|
||||
def __init__(self, first_name: Optional[str] = None, last_name: Optional[str] = None,
|
||||
location_id: Optional[int] = None, supervisor_id: Optional[int] = None,
|
||||
staff: Optional[bool] = False, active: Optional[bool] = False):
|
||||
|
@ -47,7 +47,7 @@ class User(db.Model, ImageAttachable):
|
|||
def __repr__(self):
|
||||
return f"<User(id={self.id}, first_name={repr(self.first_name)}, last_name={repr(self.last_name)}, " \
|
||||
f"location={repr(self.location)}, staff={self.staff}, active={self.active})>"
|
||||
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue