def create_tree(self, stringtree):
        names = stringtree.split()
        models = [Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species]
        assert len(names) == len(models), (names, models)

        parent = None
        for name, model in zip(names, models):
            try:
                obj = model.objects.get(name=name)
            except model.DoesNotExist:
                obj = model(name=name)
            if parent:
                setattr(obj, parent.__class__.__name__.lower(), parent)
            obj.save()
            parent = obj
Helper to create a complete tree.
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.4/tests/modeltests/select_related/tests.py/SelectRelatedTests.create_tree