def _get_or_create_section(self, name, parent): if name in self.data['section_by_name']: return self.data['section_by_name'][name].tree.get() else: section = Section(name=name, slug=urlify(name)) section.save() section_tree_item = TreeItem(parent=parent, content_object=section) section_tree_item.save() self.data['section_by_name'].update({section.name: section}) logging.debug('[S] === %s ===' % section) return section_tree_item
def create_item(self, item_params): try: target_tree_item = TreeItem.objects.get(name=u'Импорт') except TreeItem.DoesNotExist: target_tree_item = TreeItem(parent_id=None, name=u'Импорт') target_tree_item.save() target_section = Section(is_meta_item=False) target_section.save() target_tree_item.section = target_section target_tree_item.save() new_tree_item = TreeItem(name=item_params['name'][:200], parent=target_tree_item) new_item = Item( price=item_params['price'], identifier=item_params['identifier'], quantity=item_params['quantity'], ) new_tree_item.save() new_item.save() new_tree_item.item = new_item new_tree_item.save()