Add the Product.complete_size convenience attribute

also define `str(VendorItem)`
This commit is contained in:
Lance Edgar 2021-02-15 12:59:21 -06:00
parent 7cf4ec1295
commit b40fbf7cab

View file

@ -611,6 +611,18 @@ class Product(Base):
fields = filter(bool, fields)
return ' '.join(fields)
@property
def complete_size(self):
"""
Returns the "complete" size string for the product. This is based on
the :attr:`size` and :attr:`unit_of_measure` attributes.
"""
parts = [self.size, self.unit_of_measure]
parts = [(part or '').strip()
for part in parts]
parts = [part for part in parts if part]
return " ".join(parts).strip()
def __str__(self):
return self.description or ''
@ -771,6 +783,9 @@ class VendorItem(Base):
modified = sa.Column(sa.DateTime(), nullable=True)
def __str__(self):
return "{} from {}".format(self.sku, self.vendor)
class ScaleItem(Base):
"""