Beispiel #1
0
 def _get_o_products(self):
     product_ids = [
         item['product_id'] for item in self.products
         if 'product_id' in item
     ]
     o_products = Product.get_models_by_ids_with_img(product_ids,
                                                     with_for_update=True,
                                                     throw=True)
     return o_products
Beispiel #2
0
 def get_like_products(cls, member_id, start=0, count=6, soft=True, *, throw=False):
     """获取某一会员点赞的所有商品(分页)"""
     statement = cls.query.filter_by(soft=soft, member_id=member_id, like_status=True)
     total = statement.count()
     likes = statement.order_by(cls.id.desc()).offset(start).limit(count).all()
     if not likes:
         if not throw:
             return []
         else:
             raise NotFound(msg='对不起, 还没有点赞的商品')
     product_ids = [like.product_id for like in likes]
     products = Product.get_models_by_ids_with_img(product_ids, throw=True)
     return {
         'total': total,
         'start': start,
         'count': count,
         'models': products
     }