Exemplo n.º 1
0
def import_ws_product_detail(re_notice):
    msg = ''
    success_ids = []
    for j in re_notice:

        p = Product.objects.filter(choies_sku=re_notice[j]['model']).first()
        if p:
            continue
            pass
        else:
            try:
                product = Product()
                product.category_id = re_notice[j]['category']
                product.name = re_notice[j]['name']
                product.cn_name = re_notice[j]['cn_name']
                product.cost = re_notice[j]['cost']
                product.manager_id = 1
                product.choies_sku = re_notice[j]['model']
                product.weight = re_notice[j]['weight']
                product.description = re_notice[j]['size']
                product.choies_supplier_name = re_notice[j]['supplier_name']
                product.choies_site_url = re_notice[j]['site_url']
                product.price = re_notice[j]['other']
                product.save()
                success_ids.append(product.id)

                supplier = Supplier.objects.filter(
                    deleted=False, name=re_notice[j]['supplier_name']).first()
                if not supplier:
                    supplier = Supplier.objects.create(
                        name=re_notice[j]['supplier_name'])

            except Exception, e:
                msg += "失败创建product:%s%s%s |" % (
                    re_notice[j]['model'], re_notice[j]['category'], str(e))