Compare commits

...

2 commits

5 changed files with 9 additions and 10 deletions

View file

@ -39,7 +39,7 @@ class Inventory(db.Model, ImageAttachable):
location: Mapped[Optional['Room']] = relationship('Room', back_populates='inventory')
owner = relationship('User', back_populates='inventory')
brand: Mapped[Optional['Brand']] = relationship('Brand', back_populates='inventory')
item: Mapped['Item'] = relationship('Item', back_populates='inventory')
# item: Mapped['Item'] = relationship('Item', back_populates='inventory')
work_logs: Mapped[List['WorkLog']] = relationship('WorkLog', back_populates='work_item')
image: Mapped[Optional['Image']] = relationship('Image', back_populates='inventory', passive_deletes=True)
type: Mapped[Optional['Item']] = relationship('Item', back_populates='inventory')
@ -68,8 +68,8 @@ class Inventory(db.Model, ImageAttachable):
if self.name:
parts.append(f"name={repr(self.name)}")
if self.item:
parts.append(f"item={repr(self.item.description)}")
if self.type:
parts.append(f"item={repr(self.type.description)}")
if self.notes:
parts.append(f"notes={repr(self.notes)}")

View file

@ -16,9 +16,9 @@ class Item(ValidatableMixin, db.Model):
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
description: Mapped[Optional[str]] = mapped_column(Unicode(255), nullable=True)
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='item')
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='type')
def __init__(self, description: Optional[str] = None, category: Optional[str] = None):
def __init__(self, description: Optional[str] = None):
self.description = description
def __repr__(self):
@ -27,8 +27,7 @@ class Item(ValidatableMixin, db.Model):
def serialize(self):
return {
'id': self.id,
'name': self.description,
'category': self.category
'name': self.description
}
@property

View file

@ -18,7 +18,7 @@ inventory_headers = {
"Bar Code": lambda i: {"text": i.barcode},
"Brand": lambda i: {"text": i.brand.name} if i.brand else {"text": None},
"Model": lambda i: {"text": i.model},
"Item Type": lambda i: {"text": i.item.description} if i.item else {"text": None},
"Item Type": lambda i: {"text": i.type.description} if i.type else {"text": None},
"Shared?": lambda i: {"text": i.shared, "type": "bool", "html": checked_box if i.shared else unchecked_box},
"Owner": lambda i: {"text": i.owner.identifier, "url": url_for("main.user", id=i.owner.id)} if i.owner else {"text": None},
"Location": lambda i: {"text": i.location.identifier} if i.location else {"Text": None},

View file

@ -224,7 +224,7 @@ def get_inventory_csv():
case "owner":
return item.owner.identifier
case "type":
return item.item.description
return item.type.description
case _:
return getattr(item, col, "")
except Exception:

View file

@ -12,7 +12,7 @@ def eager_load_inventory_relationships(query):
return query.options(
joinedload(Inventory.owner),
joinedload(Inventory.brand),
joinedload(Inventory.item),
joinedload(Inventory.type),
selectinload(Inventory.location).selectinload(Room.room_function)
)