當前位置: 首頁>>代碼示例>>Python>>正文


Python Product.created方法代碼示例

本文整理匯總了Python中products.models.Product.created方法的典型用法代碼示例。如果您正苦於以下問題:Python Product.created方法的具體用法?Python Product.created怎麽用?Python Product.created使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在products.models.Product的用法示例。


在下文中一共展示了Product.created方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _product

# 需要導入模塊: from products.models import Product [as 別名]
# 或者: from products.models.Product import created [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 created [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.created方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。