Question: I never really understood the point of binding, beyond it being effectively shorthand for addeventlistener.

is there more to it? am I missing something?

thanks,
dsdsdsdsd

Answer: 
You might want to look into using a MPTT such as [**`django-mptt`**](http://code.google.com/p/django-mptt/)

---

this **can** be implemented by a custom filter with an [**`inclusion_tag`**](http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags) that includes itself but causes a lots of queries to your db:

```
@register.inclusion_tag('children.html')
def comments_tree(comment):
    children = comment.comment_set.all()
    return {'children': children}

# children.html

<ul>
    {% for child in children %}
    <li> <a href="{{ child.get_absolute_url }}">{{ child }}</a></li>
        {% if child.comment_set.count > 0 %}
        {% comments_tree child %}
        {% endif %}
    {% endfor %}
</ul>

# your template

{% comments_tree comment %}

```

This older question is probably of interest:

[How can I render a tree structure (recursive) using a django template?](https://stackoverflow.com/questions/32044/how-can-i-render-a-tree-structure-recursive-using-a-django-template)
**Edit**: to future readers, don't do this as the inner `for` loop's `comment` variable does not substitute the outer `comment` variable during the loop execution, leading to infinite recursion. **/Edit**

If you need a recursive tree structure in your HTML page (i.e. a bunch of nested `<div>` tags), you can write a recursive "comment" template.

**Sample**: (untested)

```
{# comment.html #}
<p class='comment'>{{ comment.text }}</p>
{% if comment.children %}
   {% for comment in comment.children %}
      {% include "comment.html" %}
   {% endfor %}
{% endfor %}

```

The for loop binds the `comment` template variable to each child before including itself.

**Performance note**: Unless your comment sets are often short, this will probably be very slow. I recommend that you make your comments non-editable and cache the result!

**Alternate solution**: If you don't need the recursive HTML `<div>` tags, you can write a generator that performs a pre-order traversal of the structure and yields `(depth, comment)` pairs. This would likely be *far* more efficient in rendering speed.