def postsave_hook(self, sess): # get all the special values try: shop_product = ShopProduct.objects.get(product=sess.instance) except: shop_product = ShopProduct() shop_product.shop = sess.shop shop_product.product = sess.instance shop_product.save() matched_fields = [] for k, v in six.iteritems(sess.importer.extra_matches): if k.startswith("ShopProduct:"): x, field = k.split(":") matched_fields.append(field) val = sess.row.get(v) setattr(shop_product, field, val) for k, v in sess.importer.data_map.items(): field_name = v.get("id") if hasattr(shop_product, field_name): field = getattr(shop_product, field_name) value = sess.row.get(k, None) if isinstance(field, PriceProperty): value = sess.shop.create_price(value) value, is_related = self._find_related_values(field_name, sess, value) if is_related and isinstance(value, six.string_types): continue setattr(shop_product, field_name, value) shop_product.save()
def postsave_hook(self, sess): # get all the special values try: shop_product = ShopProduct.objects.get(product=sess.instance) except: shop_product = ShopProduct() shop_product.shop = sess.shop shop_product.product = sess.instance shop_product.save() matched_fields = [] for k, v in six.iteritems(sess.importer.extra_matches): if k.startswith("ShopProduct:"): x, field = k.split(":") matched_fields.append(field) val = sess.row.get(v) setattr(shop_product, field, val) for k, v in sess.importer.data_map.items(): field_name = v.get("id") if field_name in self.fields_to_skip: continue if hasattr(shop_product, field_name): field = getattr(shop_product, field_name) value = sess.row.get(k, None) if isinstance(field, PriceProperty): value = sess.shop.create_price(value) value, is_related = self._find_related_values(field_name, sess, value) if is_related and isinstance(value, six.string_types): continue setattr(shop_product, field_name, value) shop_product.save()
def get_shop_instance(self, shop): try: shop_product = self.object.get_shop_instance(shop) except ShopProduct.DoesNotExist: shop_product = ShopProduct(shop=shop, product=self.object) return shop_product