Add support for tree and DAG like structures.

Object which have dependencies to other object in the model (table)
were not guaranteed to be output in the depended free order.

This fixes this problem
An attempt to make the python template work for tree link lists
Typo fix to template code
Update the default template so it can build dataset with internal refs.

We should probably make this a advanced template option and reinstate
the exiting template.

But I also think the whole template API needs a bit of refactoring
Export the new RefProperty class