Refactor inventory model relationships to replace 'item' with 'type' for improved clarity and consistency
This commit is contained in:
parent
193c2aec70
commit
da60b971f8
5 changed files with 8 additions and 9 deletions
|
@ -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)}")
|
||||
|
|
|
@ -18,7 +18,7 @@ class Item(ValidatableMixin, db.Model):
|
|||
|
||||
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='item')
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue