def create_from_sequence(bits):
 if (len(bits) == 1):
  name = bits[0]
  try:
   root = Category.objects.get(depth=1, name=name)
  except Category.DoesNotExist:
   root = Category.add_root(name=name)
  except Category.MultipleObjectsReturned:
   raise ValueError(('There are more than one categories with name %s at depth=1' % name))
  return [root]
 else:
  parents = create_from_sequence(bits[:(-1)])
  (parent, name) = (parents[(-1)], bits[(-1)])
  try:
   child = parent.get_children().get(name=name)
  except Category.DoesNotExist:
   child = parent.add_child(name=name)
  except Category.MultipleObjectsReturned:
   raise ValueError(('There are more than one categories with name %s which are children of %s' % (name, parent)))
  parents.append(child)
  return parents

def create_from_sequence ( bits ) : if ( len ( bits ) == 1 ) : name = bits [ 0 ] try : root = Category . objects . get ( depth = 1 , name = name ) except Category . DoesNotExist : root = Category . add_root ( name = name ) except Category . MultipleObjectsReturned : raise ValueError ( ( 'There are more than one categories with name %s at depth=1' % name ) ) return [ root ] else : parents = create_from_sequence ( bits [ : ( - 1 ) ] ) ( parent , name ) = ( parents [ ( - 1 ) ] , bits [ ( - 1 ) ] ) try : child = parent . get_children ( ) . get ( name = name ) except Category . DoesNotExist : child = parent . add_child ( name = name ) except Category . MultipleObjectsReturned : raise ValueError ( ( 'There are more than one categories with name %s which are children of %s' % ( name , parent ) ) ) parents . append ( child ) return parents
create categories from an iterable .