11-6 商品库存和销量修改

    xiaoxiao2022-07-03  117

    1.库存数量

    def perform_create(self, serializer): shop_cart = serializer.save() goods = shop_cart.goods goods.goods_num -= shop_cart.nums goods.save() def perform_destroy(self, instance): goods = instance.goods goods.goods_num += instance.nums goods.save() instance.delete() def perform_update(self, serializer): existed_record = ShoppingCart.objects.get(id=serializer.instance.id) existed_nums = existed_record.nums saved_record = serializer.save() nums = saved_record.nums -existed_nums goods = saved_record.goods goods.goods_num -= nums goods.save()

     

     

     

    2.销量

    order_goods = existed_order.goods.all() for order_good in order_goods: goods = order_good.goods goods.sold_num += order_good.goods_num goods.save()

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    最新回复(0)