Compare commits
2 commits
a76d19706c
...
b990805566
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b990805566 | ||
|
|
cc13321bbc |
4 changed files with 87 additions and 0 deletions
16
inventory/models/device_type.py
Normal file
16
inventory/models/device_type.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from sqlalchemy import Unicode
|
||||||
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
|
||||||
|
from crudkit.core.base import Base, CRUDMixin
|
||||||
|
|
||||||
|
class DeviceType(Base, CRUDMixin):
|
||||||
|
__tablename__ = 'item'
|
||||||
|
|
||||||
|
description: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||||
|
|
||||||
|
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='device_type')
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<Item(id={self.id}, description={repr(self.description)})>"
|
||||||
24
inventory/models/room.py
Normal file
24
inventory/models/room.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from sqlalchemy import ForeignKey, Integer, Unicode
|
||||||
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
|
||||||
|
from crudkit.core.base import Base, CRUDMixin
|
||||||
|
|
||||||
|
class Room(Base, CRUDMixin):
|
||||||
|
__tablename__ = 'rooms'
|
||||||
|
|
||||||
|
name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||||
|
|
||||||
|
area: Mapped[Optional['Area']] = relationship('Area', back_populates='rooms')
|
||||||
|
area_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("area.id"), nullable=True, index=True)
|
||||||
|
|
||||||
|
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='location')
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<Room(id={self.id}, name={repr(self.name)}, area={repr(self.area.name)}, function={repr(self.room_function.description)})>"
|
||||||
16
inventory/models/room_function.py
Normal file
16
inventory/models/room_function.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from sqlalchemy import Unicode
|
||||||
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
|
||||||
|
from crudkit.core.base import Base, CRUDMixin
|
||||||
|
|
||||||
|
class RoomFunction(Base, CRUDMixin):
|
||||||
|
__tablename__ = "room_function"
|
||||||
|
|
||||||
|
description: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||||
|
|
||||||
|
rooms: Mapped[List['Room']] = relationship('Room', back_populates='room_function')
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<RoomFunction(id={self.id}, description={repr(self.description)})>"
|
||||||
31
inventory/models/user.py
Normal file
31
inventory/models/user.py
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from sqlalchemy import Boolean, Integer, ForeignKey, Unicode
|
||||||
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
|
||||||
|
from crudkit.core.base import Base, CRUDMixin
|
||||||
|
|
||||||
|
class User(Base, CRUDMixin):
|
||||||
|
__tablename__ = 'users'
|
||||||
|
|
||||||
|
first_name: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
|
||||||
|
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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='owner')
|
||||||
|
|
||||||
|
location: Mapped[Optional['Room']] = relationship('Room', back_populates='owner')
|
||||||
|
location_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
|
||||||
|
|
||||||
|
supervisor: Mapped[Optional['User']] = relationship('User', back_populates='subordinates')
|
||||||
|
supervisor_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("user.id"), nullable=True, index=True)
|
||||||
|
subordinates: Mapped[List['User']] = relationship('User', back_populates='supervisor')
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<User(id={self.id}, first_name={repr(self.first_name)}, last_name={repr(self.last_name)})>"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue