@classmethod<EOL><INDENT>def create_tree(cls, stringtree):<DEDENT>
names = stringtree.split()<EOL>models = [Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species]<EOL>assert len(names) == len(models), (names, models)<EOL>parent = None<EOL>for name, model in zip(names, models):<EOL><INDENT>try:<EOL><INDENT>obj = model.objects.get(name=name)<EOL><DEDENT>except model.DoesNotExist:<EOL><INDENT>obj = model(name=name)<EOL><DEDENT>if parent:<EOL><INDENT>setattr(obj, parent.__class__.__name__.lower(), parent)<EOL><DEDENT>obj.save()<EOL>parent = obj<EOL><DEDENT>
Helper to create a complete tree.