def save_cat_heirarchy(self,category,parent): client = Client.objects.get(name='bigbazaar') try: cat = Category.objects.get(ext_id=category['category_id'],client=client) except Category.DoesNotExist: cat = Category() cat.name = category['display_name'] cat.ext_id = category['category_id'] cat.slug = slugify(cat.name) cat.client = client cat.save() if parent: parent = Category.objects.get(ext_id=parent['category_id'],client=client) try: cat_graph = CategoryGraph.objects.get(category=cat,parent=parent) except CategoryGraph.DoesNotExist: cat_graph = CategoryGraph() cat_graph.category = cat cat_graph.parent = parent cat_graph.save()