fix: add Product.default_vendor_item
convenience property
This commit is contained in:
parent
8359e5692e
commit
9b9260ba4b
|
@ -583,6 +583,32 @@ class Product(common.ProductBase, Base):
|
||||||
creator=lambda lc: ProductLikeCode(like_code=lc),
|
creator=lambda lc: ProductLikeCode(like_code=lc),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
vendor_items = orm.relationship(
|
||||||
|
'VendorItem',
|
||||||
|
back_populates='product',
|
||||||
|
primaryjoin='VendorItem.upc == Product.upc',
|
||||||
|
foreign_keys='VendorItem.upc',
|
||||||
|
order_by='VendorItem.vendor_item_id',
|
||||||
|
doc="""
|
||||||
|
List of :class:`VendorItem` records for this product.
|
||||||
|
""")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def default_vendor_item(self):
|
||||||
|
"""
|
||||||
|
Returns the "default" vendor item record. This will
|
||||||
|
correspond to the :attr:`default_vendor` if possible.
|
||||||
|
|
||||||
|
:rtype: :class:`VendorItem` or ``None``
|
||||||
|
"""
|
||||||
|
if self.default_vendor:
|
||||||
|
for item in self.vendor_items:
|
||||||
|
if item.vendor_id == self.default_vendor.id:
|
||||||
|
return item
|
||||||
|
|
||||||
|
if self.vendor_items:
|
||||||
|
return self.vendor_items[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_description(self):
|
def full_description(self):
|
||||||
fields = ['brand', 'description', 'size']
|
fields = ['brand', 'description', 'size']
|
||||||
|
@ -732,17 +758,12 @@ class VendorItem(Base):
|
||||||
upc = sa.Column(sa.String(length=13), nullable=False)
|
upc = sa.Column(sa.String(length=13), nullable=False)
|
||||||
product = orm.relationship(
|
product = orm.relationship(
|
||||||
Product,
|
Product,
|
||||||
|
back_populates='vendor_items',
|
||||||
primaryjoin=Product.upc == upc,
|
primaryjoin=Product.upc == upc,
|
||||||
foreign_keys=[upc],
|
foreign_keys=[upc],
|
||||||
doc="""
|
doc="""
|
||||||
Reference to the :class:`Product` to which this record applies.
|
Reference to the :class:`Product` to which this record applies.
|
||||||
""",
|
""")
|
||||||
backref=orm.backref(
|
|
||||||
'vendor_items',
|
|
||||||
order_by=vendor_item_id,
|
|
||||||
doc="""
|
|
||||||
List of :class:`VendorItem` records for this product.
|
|
||||||
"""))
|
|
||||||
|
|
||||||
brand = sa.Column(sa.String(length=50), nullable=True)
|
brand = sa.Column(sa.String(length=50), nullable=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue