def make_product_group(similar_products): product_group = {} product_group['sku'] = similar_products[0].sku product_group['short_description'] = similar_products[0].short_description product_group['description'] = similar_products[0].description product_group['price'] = similar_products[0].price attributes = [] attribute_titles = get_attribute_titles(similar_products) for i,product in enumerate(similar_products,start=1): attribute = {} attribute['name'] = attribute_titles[i] attribute['sku'] = product.sku attribute['short_description'] = product.short_description attribute['description'] = product.description attribute['price'] = product.price attributes.append(attribute) product_group['name'] = similar_products[0].name # save to database for product in similar_products: product.delete() head_product = similar_products[0] head_product.save() # save attributes for attribute_map in attributes: attribute = Attribute(attribute_map) attribute.save() return product_group
null_price = True if not null_price: product.save() else: products_not_added.append(product.sku) # has_valid_prices = True # attributes = [] # print "saved " + str(product) # print "saved product "+ str(product.sku) for datas in similar_rows: if(not null_price): attribute = Attribute(product=product) attribute.name = datas[3].string.encode('ascii', 'ignore') attribute.price = decimal.Decimal(get_price(datas)) if attribute.price == 0: try: p = Product.objects.filter(sku=datas[1].string[1:]).get() attribute.price = p.price except: # has_valid_prices = False # print "attribute had no previous price, sku = " + datas[1].string[1:] products_not_added.append(datas[1].string[1:]) null_price = True attribute.sku = datas[1].string[1:] attribute.description = datas[5].string attribute.short_description = datas[11].string