当前位置: 首页>>代码示例>>Python>>正文


Python Product.quantity方法代码示例

本文整理汇总了Python中products.models.Product.quantity方法的典型用法代码示例。如果您正苦于以下问题:Python Product.quantity方法的具体用法?Python Product.quantity怎么用?Python Product.quantity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在products.models.Product的用法示例。


在下文中一共展示了Product.quantity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _product

# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import quantity [as 别名]
    def _product(self, item):
        try:
            product = Product.objects.get(wholesale_legacy_id=int(item['id']), is_visible=True)
        except Product.DoesNotExist:
            product = Product()
        except Product.MultipleObjectsReturned:
            print item['id']
            for p in Product.objects.filter(wholesale_legacy_id=int(item['id'])):
                print p.id, p.title, p.code, p.sku
            print '-----'
            raise

        quantity = int(item.get('qtyi', 0))
        if quantity < 0:
            quantity = 0

        weight = int(item.get('weight', 0))
        if weight < 0:
            weight = 0

        product.sku = item['article']
        product.weight = weight
        product.quantity = quantity
        product.code = item['link']
        product.title = item['name']
        product.description = item['descr']
        product.is_visible = bool(int(item['pub']))
        product.wholesale_legacy_id = item['id']
        product.created = TIMEZONE.localize(datetime.datetime.fromtimestamp(int(item['dt'])))

        size = None
        try:
            size = SIZE_RE.findall(u' '.join([item['name'], item.get('alt', ''), item['descr']]))[0]
        except IndexError:
            try:
                size = SIZE2_RE.findall(u' '.join([item['name'], item.get('alt', ''), item['descr']]))[0]
            except IndexError:
                pass

        if size:
            product.size = u'×'.join([str(x) for x in size])

        return product
开发者ID:Lisaveta-K,项目名称:lisaveta-k.github.io,代码行数:45,代码来源:products_wholesale_import.py

示例2: _product

# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import quantity [as 别名]
    def _product(self, item):
        try:
            product = Product.objects.get(id=int(item['id']))
        except Product.DoesNotExist:
            product = Product(id=int(item['id']))

        quantity = int(item.get('qtyi', 0))
        if quantity < 0:
            quantity = 0

        weight = int(item.get('weight', 0))
        if weight < 0:
            weight = 0

        product.sku = item['article']
        product.weight = weight
        product.quantity = quantity
        product.code = item['link']
        product.title = item['name']
        product.description = item['descr']
        product.is_visible = bool(int(item['pub']))
        product.is_wholesale = False
        product.created = TIMEZONE.localize(datetime.datetime.fromtimestamp(int(item['dt'])))

        size = None
        try:
            size = SIZE_RE.findall(u' '.join([item['name'], item.get('alt', ''), item['descr']]))[0]
        except IndexError:
            try:
                size = SIZE2_RE.findall(u' '.join([item['name'], item.get('alt', ''), item['descr']]))[0]
            except IndexError:
                pass

        if size:
            product.size = u'×'.join([str(x) for x in size])

        return product
开发者ID:Lisaveta-K,项目名称:lisaveta-k.github.io,代码行数:39,代码来源:products_import.py


注:本文中的products.models.Product.quantity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。